Open ambujshukla opened 9 years ago
// // ViewController.m // TwitterSharing // // Created by cdn105 on 23/04/15. // Copyright (c) 2015 CDN. All rights reserved. //
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UILabel *lblUserName; @property (nonatomic, assign) BOOL isStreaming;
@end
@implementation ViewController
//Used for Login -(IBAction)actionLoginButton:(id)sender { [self loginOAuth]; }
-(IBAction)actionLogoutButton:(id)sender { [self logout]; }
-(IBAction)actionPostTwitButton:(id)sender { if([[FHSTwitterEngine sharedEngine]isAuthorized]) [self postTweet]; else [self loginOAuth]; }
-(void)decorateUI { [[FHSTwitterEngine sharedEngine]permanentlySetConsumerKey:@"Xg3ACDprWAH8loEPjMzRg" andSecret:@"9LwYDxw1iTc6D9ebHdrYCZrJP4lJhQv5uf4ueiPHvJ0"]; [[FHSTwitterEngine sharedEngine]setDelegate:self]; [[FHSTwitterEngine sharedEngine]loadAccessToken]; }
(void)alertView:(UIAlertView )alertView clickedButtonAtIndex:(NSInteger)buttonIndex { if ([alertView.title isEqualToString:@"Tweet"]) { NSString tweet = [alertView textFieldAtIndex:0].text; UIImage image=[UIImage imageNamed:@"button_bg.png"]; NSData imgData=UIImagePNGRepresentation(image); [self doTweetWithMessage:tweet andImageData:imgData]; } else { if (buttonIndex == 1) { NSString username = [alertView textFieldAtIndex:0].text; NSString password = [alertView textFieldAtIndex:1].text;
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
@autoreleasepool {
// getXAuthAccessTokenForUsername:password: returns an NSError, not id.
NSError *returnValue = [[FHSTwitterEngine sharedEngine]getXAuthAccessTokenForUsername:username password:password];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
dispatch_sync(dispatch_get_main_queue(), ^{
@autoreleasepool {
NSString *title = returnValue?[NSString stringWithFormat:@"Error %ld",(long)returnValue.code]:@"Success";
NSString *message = returnValue?returnValue.localizedDescription:@"You have successfully logged in via XAuth";
UIAlertView *av = [[UIAlertView alloc]initWithTitle:title message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[av show];
//[_theTableView reloadData];
}
});
}
});
}
} }
-(void)doTweetWithMessage:(NSString )strTitle andImageData:(NSData )imgData { [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ @autoreleasepool {
//id returned = [[FHSTwitterEngine sharedEngine]postTweet:tweet];
id returned = [[FHSTwitterEngine sharedEngine] postTweet:strTitle withImageData:imgData];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
NSString *title = nil;
NSString *message = nil;
if ([returned isKindOfClass:[NSError class]]) {
NSError *error = (NSError *)returned;
title = [NSString stringWithFormat:@"Error %ld",(long)error.code];
message = error.localizedDescription;
} else {
NSLog(@"%@",returned);
title = @"Tweet Posted";
message = strTitle;
}
dispatch_sync(dispatch_get_main_queue(), ^{
@autoreleasepool {
//Show message when
[self showAlertWithMessage:message];
}
});
}
});
}
(void)logTimeline { [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ @autoreleasepool { NSLog(@"%@",[[FHSTwitterEngine sharedEngine]getTimelineForUser:[[FHSTwitterEngine sharedEngine]authenticatedID] isID:YES count:10]);
dispatch_sync(dispatch_get_main_queue(), ^{
@autoreleasepool {
[[[UIAlertView alloc]initWithTitle:@"Complete" message:@"Your list of followers has been fetched. Check your debugger." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]show];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
});
}
}); }
(void)postTweet { NSString tweet =@"Hello"; UIImage image=[UIImage imageNamed:@"button_bg.png"]; NSData *imgData=UIImagePNGRepresentation(image);
[self doTweetWithMessage:tweet andImageData:imgData]; }
-(void)showAlertWithMessage:(NSString )strMsg { UIAlertView alert=[[UIAlertView alloc] initWithTitle:@"Twitter Sharing" message:strMsg delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; }
@end
SWRevealViewController revealController = self.revealViewController; UINavigationController navigationController; switch (indexPath.row) { case 0:{ BTWDashboardDataEmailViewController * rootView = [[BTWDashboardDataEmailViewController alloc] initWithNibName:@"BTWDashboardDataEmailViewController" bundle:nil]; navigationController = [appDelegate.revealNavigation initWithRootViewController:rootView]; [revealController pushFrontViewController:navigationController animated:YES];
// // ViewController.m // TTS // // Created by Ambuj Shukla on 29/04/15. // Copyright (c) 2015 Test. All rights reserved. //
import "ViewController.h"
import <AVFoundation/AVFoundation.h>
@interface ViewController ()
{
AVSpeechSynthesizer synthesizer;
}
@property (nonatomic,strong) IBOutlet UILabel lbl;
@end
@implementation ViewController
pragma mark - AVSpeechSynthesizerDelegate
@end