I am working on MPMediaplayerviewcontroller for video player in ios.. It is working fine..I am integrating Facebook and twitter for mediaplayerviewcontroller. After completion of app launch Facebook and twitter are not working..after coming from background to foreground it is working good..
This is my code.. plz help me any body. Thanks in advance…
-(void)viewDidLoad
{
mp = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
[mp.view setFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height)];
[self presentMoviePlayerViewControllerAnimated:mp];
mp.view.frame = self.view.bounds; //Set the size
self.view.backgroundColor=[UIColor clearColor];
mp.moviePlayer.controlStyle =MPMovieControlStyleNone;
mp.moviePlayer.repeatMode = MPMovieRepeatModeOne;
mp.moviePlayer.view.userInteractionEnabled = YES;
mp.moviePlayer.movieSourceType=MPMovieSourceTypeStreaming;
[[NSNotificationCenter defaultCenter]addObserver:self selector:#selector(EnteredForeground) name:#"WillEnterForeGround" object:nil];
mp.moviePlayer prepareToPlay];
[mp.moviePlayer prepareToPlay];
[mp.moviePlayer play];
[self.view addSubview:mp.view];
-(void)EnteredForeground
{
[self.view addSubview:mp.view];
[[mp moviePlayer] play];
}
-(void)sharingAction
{
action=[[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle: nil destructiveButtonTitle: nil otherButtonTitles:#"Facebook",#"Twitter",#"Cancel", nil];
[action showInView:self.mp.moviePlayer.view];
}
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
switch(buttonIndex)
{
case 0:
[self signInFb];
break;
case 1:
[self signInTwitter];
break;
default:
[self Cancel];
break;
}
}
-(void)signInFb
{
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled) {
alert=[[UIAlertView alloc]initWithTitle:#"warning" message:#"Your post canceled" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
else if(oResponseData1!=nil)
{
facebookSuccessAlert=[[UIAlertView alloc]initWithTitle:#"success" message:#"Your post succesfully send" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[facebookSuccessAlert show];
}
[controller dismissViewControllerAnimated:YES completion:Nil];
};
controller.completionHandler =myBlock;
[controller setInitialText:VideoUrlString];
[controller addImage:[UIImage imageNamed:#"appIcon900x900.png"]];
[self presentViewController:controller animated:YES completion:Nil];
}
else{
NSLog(#"UnAvailable");
}
}
Related
My code for share screenshot of my App in Facebook always shows alertView and never posts in Facebook:
- (UIImage *) screenshot
{
AppDelegate* app = (((AppDelegate*)[UIApplication sharedApplication].delegate));
UIGraphicsBeginImageContextWithOptions(app.navController.view.bounds.size, NO, [UIScreen mainScreen].scale);
[app.navController.view drawViewHierarchyInRect:app.navController.view.bounds afterScreenUpdates:YES];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
-(void)btnSharedFacebookTapped:(id)sender
{
[[AudioManager sharedAudioManager]playSoundEffect:kSoundGrilloMenu];
// Take screenshot
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
AppDelegate* app = (((AppDelegate*)[UIApplication sharedApplication].delegate));
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result)
{
if (result == SLComposeViewControllerResultCancelled)
{
NSLog(#"Cancelled");
} else {
NSLog(#"Done");
}
[app.navController dismissViewControllerAnimated:YES completion:Nil];
};
controller.completionHandler =myBlock;
//Adding the Text to the facebook post value from iOS
[controller setInitialText:#"Checkout this app xxxxxx”];
[controller addImage:[self screenshot]];
//Adding the URL to the facebook post value from iOS
[controller addURL:[NSURL URLWithString:#"https://itunes.apple.com/us/app/xxxxxxx/id[xxx]?mt=8"]];
[app.navController presentViewController:controller animated:YES completion:Nil];
} else{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Sorry"
message:#"You can't send a post right now, make sure your device has an internet connection and you have at least one Facebook account setup."
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
}
I have created one demo APP for this. In this APP, i am posting status and uploading photo but i have never got fail error.
- (IBAction)btnSocialSharing:(id)sender {
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"Select Social Media"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:#"Facebook", #"Twitter" ,nil];
// actionSheet.tag = 100;
[actionSheet showInView:self.view];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *buttonTitle=[actionSheet buttonTitleAtIndex:buttonIndex];
// NSString *image=[UIImage imageNamed:chooseImage];
if ([buttonTitle isEqualToString:#"Facebook"])
{
SLComposeViewController *controller = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler myBlock =
^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled)
{
NSLog(#"Cancelled");
}
else
{
NSLog(#"Done");
}
[controller dismissViewControllerAnimated:YES completion:nil];
};
controller.completionHandler =myBlock;
[controller setInitialText:self.txtStatus.text];
[controller addImage:chooseImage];
[self presentViewController:controller animated:YES completion:nil];
}
else if ([buttonTitle isEqualToString:#"Twitter"])
{
SLComposeViewController *controller = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
SLComposeViewControllerCompletionHandler myBlock =
^(SLComposeViewControllerResult result){
if (result == SLComposeViewControllerResultCancelled)
{
NSLog(#"Cancelled");
}
else
{
NSLog(#"Done");
}
[controller dismissViewControllerAnimated:YES completion:nil];
};
controller.completionHandler =myBlock;
[controller setInitialText:self.txtStatus.text];
[controller addImage:chooseImage];
[self presentViewController:controller animated:YES completion:nil];
}
}
- (IBAction)btnSelectPhoto:(id)sender {
NSLog(#"Select Photos button");
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
//Image Picker Delegate Methods
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
chooseImage = info[UIImagePickerControllerEditedImage];
[picker dismissViewControllerAnimated:YES completion:NULL];
[self displayImage];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
-(void)displayImage
{
self.viewImage.image = chooseImage;
}
I am using SLComposeViewController for sharing in Twitter and Facebook in my app. It is working fine for Twitter but for Facebook, SLComposeViewController closes automatically on selecting location. This is an iOS 8 issue. Working fine on iOS7.
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
self.fbSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result){
// [fbSheet dismissViewControllerAnimated:YES completion:nil];
switch(result){
case SLComposeViewControllerResultCancelled:
default:
{
NSLog(#"Cancelled.....");
}
break;
case SLComposeViewControllerResultDone:
{
NSLog(#"Posted....");
if([NetworkManager SharedInstance].isInternetReachable){
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:#"Success"
message:#"Feeds shared successfully."
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
}
break;
}};
[self.fbSheet setCompletionHandler:completionHandler];
NSString *fbString= self.titleString;
[self.fbSheet setInitialText:fbString];
[self.fbSheet addURL:[NSURL URLWithString:self.urlString]];
[self presentViewController:self.fbSheet animated:YES completion:nil];
}
The control is automatically going into completion handler block with result as cancelled. I have gone through some posts suggesting it is 64 bit architecture problem. Please help me with this if anyone is facing the same issue.
- (IBAction)facebookPost:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
self.fbSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[self.fbSheet setInitialText:#"Social Framework test"];
[self.fbSheet addImage:[UIImage imageNamed:#"imagename.png"]];
[self.fbSheet addURL:[NSURL URLWithString:#"URL_NAME"]];
[self.fbSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
switch (result) {
case SLComposeViewControllerResultCancelled:
NSLog(#"Post Canceled");
break;
case SLComposeViewControllerResultDone:
{
NSLog(#"Post Sucessful");
NSLog(#"Posted....");
if([NetworkManager SharedInstance].isInternetReachable){
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:#"Success"
message:#"Feeds shared successfully."
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
}
break;
default:
break;
}
}];
[self presentViewController:self.fbSheet animated:YES completion:nil];
}
}
I can load up leaderboards with no problem. But I can't get it to close when the "Done" button is clicked.
How I'm opening it:
- (IBAction)leaderboardsClicked:(id)sender{
if ([GKLocalPlayer localPlayer].isAuthenticated) {
GKGameCenterViewController *leaderboardController = [[GKGameCenterViewController alloc] init];
[self presentViewController:leaderboardController animated:YES completion:NULL];
}else{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle: #"Error"
message: #"You must be logged into Game Center to view the leaderboards. Open Game Center?"
delegate: self
cancelButtonTitle:#"No"
otherButtonTitles:#"Yes",nil];
[alert show];
}
}
How I'm closing it:
- (void)gameCenterViewControllerDidFinish:(GKGameCenterViewController *)gameCenterViewController{
NSLog(#"test");
[self dismissViewControllerAnimated:YES completion:nil];
}
EDIT:
The method isn't running at all; so "test" doesn't even get printed.
And I added <GKGameCenterControllerDelegate> to my ViewController's protocol.
Try this instead:
- (IBAction)leaderboardsClicked:(id)sender{
if ([GKLocalPlayer localPlayer].isAuthenticated) {
GKGameCenterViewController *leaderboardController = [[GKGameCenterViewController alloc] init];
leaderboardController.gameCenterDelegate = self;
gameCenterController.viewState = GKGameCenterViewControllerStateLeaderboards;
[self presentViewController:leaderboardController animated:YES completion:NULL];
}else{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle: #"Error"
message: #"You must be logged into Game Center to view the leaderboards. Open Game Center?"
delegate: self
cancelButtonTitle:#"No"
otherButtonTitles:#"Yes",nil];
[alert show];
}
}
And:
- (void) gameCenterViewControllerDidFinish:(GKGameCenterViewController*) gameCenterViewController {
[self dismissViewControllerAnimated:YES completion:nil];
}
Am using SLComposeViewController for posting articles to facebook wall.When App permission is turned off for facebook in device settings,
SLComposeViewController still Works by posting article to facebook wall.Is this a SDK issue?
SLComposeViewController *facebookViewController=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result)
{
[facebookViewController dismissViewControllerAnimated:YES completion:nil];
switch(result){
case SLComposeViewControllerResultCancelled:
default:
{
[[[UIAlertView alloc] initWithTitle:#"Facebook"
message:#"Action Cancelled"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil]
show];
[self dismissView];
}
break;
case SLComposeViewControllerResultDone:
{
[[[UIAlertView alloc] initWithTitle:#"Facebook"
message:#"Posted to Facebook successfully"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil]
show];
[self dismissView];
}
break;
}};
[facebookViewController addImage:_shareImage];
[facebookViewController setInitialText:_shareTitle];
[facebookViewController addURL:_shareLink];
[facebookViewController setCompletionHandler:completionHandler];
[self.dashboard presentViewController:facebookViewController animated:YES completion:nil];
}
I found out the answer myself.
Check the below code
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"6.0"))
{
ACAccountStore *accountStore=[[ACAccountStore alloc]init];
ACAccountType * facebookAccountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
// At first, we only ask for the basic read permission
NSArray * permissions = #[#"publish_stream"];
NSDictionary * dict = #{ACFacebookAppIdKey : #"facebook_appid", ACFacebookPermissionsKey : permissions, ACFacebookAudienceKey : ACFacebookAudienceEveryone};
[accountStore requestAccessToAccountsWithType:facebookAccountType options:dict completion:^(BOOL granted, NSError *error) {
if (granted && error == nil)
{
SLComposeViewController *facebookViewController=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result)
{
[facebookViewController dismissViewControllerAnimated:YES completion:nil];
switch(result){
case SLComposeViewControllerResultCancelled:
default:
{
[self dismissView];
}
break;
case SLComposeViewControllerResultDone:
{
[[[UIAlertView alloc] initWithTitle:#"Facebook"
message:#"Posted to Facebook successfully"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil]
show];
[self dismissView];
}
break;
}};
[facebookViewController addImage:_shareImage];
[facebookViewController setInitialText:_shareTitle];
[facebookViewController addURL:_shareLink];
[facebookViewController setCompletionHandler:completionHandler];
[self.dashboard presentViewController:facebookViewController animated:YES completion:nil];
}
else
{
dispatch_async(dispatch_get_main_queue(), ^{
[self dismissView];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"" message: #"App Permissions disabled in facebook settings."
delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alert show];
});
}
}];
In my project i am having 5 levels. In First and second level i can able to move and shoot at a time. When completing 2nd level i want to share it with Facebook. After facebook share i cant able to move and shoot at a time. Only one process is working(Either shoot or move).
What i want to do for solve this problem.
My coding is here:
{
UIViewController*v=[[UIViewController alloc]init];
[[[CCDirector sharedDirector]openGLView]addSubview:v.view];
SLComposeViewController*mySLComposerSheet;
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
NSString *strg=[NSString stringWithFormat:#" "];
NSString *bodyStr=[NSString stringWithFormat:#"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"!\n;
mySLComposerSheet = [[SLComposeViewController alloc] init];
mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook]; //Tell him with what social plattform to use it, e.g. facebook or twitter
[mySLComposerSheet setInitialText:bodyStr]; //the message you want to post
[mySLComposerSheet addImage:[UIImage imageNamed:#"my.jpg"]]; //an image you could post
NSURL *url = [NSURL URLWithString:#"https:example.com"];
[mySLComposerSheet addURL:url];
[v presentViewController:mySLComposerSheet animated:YES completion:nil];
}
[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
NSString *output,*head;
switch (result) {
case SLComposeViewControllerResultCancelled:
output = #"FREE levels NOT unlocked";
head=#"Facebook Share Unsuccessfull";
UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:head message:output delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert1 show];
[self reload];
break;
case SLComposeViewControllerResultDone:
output = #"Extra FREE levels successfully unlocked";
head=#"Successfull";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:head message:output delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
alert.tag=22;
break;
default:
break;
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Facebook" message:output delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alert show];
}];
}
You are presenting the ViewController mySLComposerSheet
[v presentViewController:mySLComposerSheet animated:YES completion:nil];
but there is no dismiss... statement in your completionHandler
[self dismissViewControllerAnimated:YES completion:nil];
see the post https://stackoverflow.com/a/12651085/2787026