i use this code ( works perfectly in IOS 7 )
mySLComposerSheet = [[SLComposeViewController alloc] init];
mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[mySLComposerSheet setInitialText:[NSString stringWithFormat:#"%#",annotazioni.text]];
[mySLComposerSheet addImage:ScreenshotForShare];
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
if (!mySLComposerSheet) {
return;
}else{
}
[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
switch (result) {
case SLComposeViewControllerResultCancelled:
NSLog(#"Post Canceled");
break;
case SLComposeViewControllerResultDone:
NSLog(#"Post Sucessful");
break;
default:
break;
}
}];
BUT, when slcomposerview appear, after 1-2 seconds disappear without any input command, in simulator and device ...
What is the correct code?
My other way for posting photo is this :
NSString *client_id = #"123456789012345"; (The same of .Plist)
fbGraph = [[FbGraph alloc] initWithFbClientID:client_id];
[fbGraph authenticateUserWithCallbackObject:self andSelector:#selector(postInAppFacebook) andExtendedPermissions:#"user_photos,user_videos,publish_stream,offline_access" andSuperView:self.view];
NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:3];
FbGraphFile *graph_file = [[FbGraphFile alloc] initWithImage:ScreenshotForShare];
[variables setObject:graph_file forKey:#"file"];
[variables setObject:[NSString stringWithFormat:#"%#",annotazioni.text] forKey:#"message"];
[fbGraph doGraphPost:#"me/photos" withPostVars:variables];
if (TwitterShare == YES) {
[self ShareOnTwitter];
}else{
[self dismissViewControllerAnimated:YES completion:nil];
}
BUT ONLY IN IOS 8 i receive error 191... On IOS 7 all works perfectly and the photo was posted on my diary correctly.
Help me plase i can't find a solution after 7 day's ...
Thank's in advance
Related
I am facing one issue for send message to multiple contacts :
301 up contacts : Message app is not opening, If we click invite on multiple time then iMessage is opening but it will take more time (2 minute) to load message
351 up contacts : Message is open with black new message screen then come back to our application with out opening message screen.
Here is my code:
contacts is the array of phone number
NSMutableArray *contacts = [NSMutableArray array];
for (User *user in users) {
if (user.phone.length) {
NSString *strphonenumber = [NSString stringWithFormat:#"%#",user.phone];
[contacts addObject:strphonenumber];
}
}
MFMessageComposeViewController *messanger = [[MFMessageComposeViewController alloc]init];
messanger.messageComposeDelegate = self;
messanger.recipients = contacts;
messanger.body = [NSString stringWithFormat:#“body”;
[self presentViewController:messanger animated:YES completion:NULL];
I am getting this error:
<CKSMSComposeRemoteViewController: 0x12802f810> timed out waiting for fence barrier from com.apple.mobilesms.compose
Try this...
NSString *strContacts = [NSString stringWithFormat:#"%#",add multipal contacts];
MFMessageComposeViewController *message = [[MFMessageComposeViewController new];
message.recipients = #[strContacts];
I to had the same problem then figured
messanger.recipients = // should always be an array of strings.
Make sure the phone numbers you send to messanger.recipients are NSString.
this works for me:
set delegate to interface:
#interface ViewController <MFMessageComposeViewControllerDelegate>{}
check if device is able to send message
if([MFMessageComposeViewController canSendText] ){
//device is possible to send messages
}else{
//device can't send messages
}
prepare message:
MFMessageComposeViewController* comp = [[MFMessageComposeViewController alloc] init];
//set properties
comp.body = #"body";
comp.recipients = [NSArray arrayWithObjects:phone1, phone2, nil];
comp.messageComposeDelegate = self;
open dialog:
[self presentViewController:comp animated:YES completion:nil];
determine result
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{
//test result
switch (result) {
case MessageComposeResultCancelled:
[self makeAlert:#"Result canceled"];
break;
//message was sent
case MessageComposeResultSent:
[self makeAlert:#"Result sent"];
break;
case MessageComposeResultFailed:
[self makeAlert:#"Result Failed"];
break;
default:
break;
}
//dismiss view
[self dismissViewControllerAnimated:YES completion:nil];
}
Just use this method:
- (IBAction)sendSMS:(id)sender {
MFMessageComposeViewController *controller =
[[MFMessageComposeViewController alloc] init] autorelease];
if([MFMessageComposeViewController canSendText]){
controller.body = #"Hello";
controller.recipients = [NSArray arrayWithObjects:#"12345678",#"87654321", nil];
controller.messageComposeDelegate = self;
[self presentViewController:controller animated:YES completion:nil];
}
}
Callback method:
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{
switch (result) {
case MessageComposeResultCancelled:
NSLog(#"Cancelled");
break;
case MessageComposeResultFailed:
NSLog(#"Error occured");
break;
case MessageComposeResultSent:
break;
default:
break;
}
[self dismissViewControllerAnimated:YES completion:nil];
}
This question already has answers here:
iOS: How to share text and image on social networks?
(3 answers)
Closed 7 years ago.
I want to share photo and some text from the app on Facebook. I used SLComposeViewController class for sharing.
My problem is that when I tap on Facebook button a dialog box appears with image which I want to post but default text is not appearing in the device while in simulator it works perfectly fine. This code works perfectly for Twitter both in simulator and device. For more clarity I added code and an image
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
SLComposeViewControllerCompletionHandler myBlock = ^(SLComposeViewControllerResult result)
{
if (result == SLComposeViewControllerResultCancelled)
{
NSLog(#"Cancelled");
} else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Congratulations!" message:#"Photo is posted to facebook Wall." delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[alert show];
}
[controller dismissViewControllerAnimated:YES completion:Nil];
};
controller.completionHandler =myBlock;
str=[NSString stringWithFormat:#"Text to share"];
[controller setInitialText:str];
[controller addImage:savedImage];
[self presentViewController:controller animated:YES completion:Nil];
}
str=#"Text to share";
[controller setInitialText:str];
OR
[controller setInitialText:#"Text to share"];
change your code like this and try...
- (IBAction)facebookPost:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[mySLComposerSheet setInitialText:#"Social Framework test!"];
[mySLComposerSheet addImage:[UIImage imageNamed:#"myImage.png"]];
[mySLComposerSheet addURL:[NSURL URLWithString:#"http://stackoverflow.com"]];
[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result) {
switch (result) {
case SLComposeViewControllerResultCancelled:
NSLog(#"Post Canceled");
break;
case SLComposeViewControllerResultDone:
NSLog(#"Post Sucessful");
break;
default:
break;
}
}];
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
}
}
Try this........This what I did for my project
I made a basic app that for now just has a button that you click, and it brings up the sms composer (ios7 and xcode 5). I think I've handled everything well. The simulator doesn't support sending messages, so I tried on my phone, but the message never actually sends. You can click the send button and cancel button fine, but again, the message never sends. Any ideas? Here is my code:
- (IBAction)text:(UIButton *)sender {
MFMessageComposeViewController *messageVC = [[MFMessageComposeViewController alloc] init];
[messageVC setMessageComposeDelegate:self];
if ([MFMessageComposeViewController canSendText]) {
NSString *smsString = [NSString stringWithFormat:#"message to send"];
messageVC.body = smsString;
messageVC.recipients = #[#"number to send to..."];
messageVC.messageComposeDelegate = self;
[self presentViewController:messageVC animated:YES completion:nil];
}
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
switch (result) {
case MessageComposeResultCancelled:
NSLog(#"Message was cancelled");
[self dismissViewControllerAnimated:YES completion:NULL]; break;
case MessageComposeResultFailed:
NSLog(#"Message failed");
[self dismissViewControllerAnimated:YES completion:NULL]; break;
case MessageComposeResultSent:
NSLog(#"Message was sent");
[self dismissViewControllerAnimated:YES completion:NULL]; break;
default:
break;
}
}
EDIT: So I tried it this morning (I did nothing to it overnight) and it worked. Not sure what the issue was. Thanks though!
I assume the messageVC.recipients is in correct format (array of numbers)?
Try:
//check if the device can send text messages
if(![MFMessageComposeViewController canSendText]) {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Your device cannot send text messages" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
return;
}
//set receipients
NSArray *recipients = [NSArray arrayWithObjects:#"0912345679",#"0923456790",#"0934567901", nil];
//set message text
NSString * message = #"this is a test sms message.";
MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init];
messageController.messageComposeDelegate = self;
[messageController setRecipients:recipients];
[messageController setBody:message];
// Present message view controller on screen
[self presentViewController:messageController animated:YES completion:nil];
Try This In Your MessageCompose Delegate:
(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
switch (result)
{
case MessageComposeResultCancelled:
NSLog(#"Message was cancelled");
break;
case MessageComposeResultFailed:
NSLog(#"Message failed");
break;
case MessageComposeResultSent:
NSLog(#"Message was sent");
break;
default:
break;
}
[controller dismissViewControllerAnimated:YES completion:nil];
}
I'm using the following method to share an image and a url to the user's Facebook wall. The problem is that because I'm adding an image with the post it ends up being saved in a Facebook photo album. Perhaps this is the default behaviour, although I swear at one point it was posting just to the wall with a photo and not to a photo album.
thanks for any help
- (IBAction)shareAction:(id)sender {
SLComposeViewController * fbController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[fbController setInitialText:#"App Name"];
NSIndexPath* indexPath = [tableView indexPathForCell:sideSwipeCell];
// NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
// output id of selected deal
#ifdef DEBUG
NSLog(#"deal id for selected row is %#", [[displayItems objectAtIndex:indexPath.row] objectForKey:#"id"]);
#endif
// display the youdeal deal image
link = [[displayItems objectAtIndex:indexPath.row] objectForKey:#"link"];
// download the youdeal deal image for FB posting
NSURL *url = [NSURL URLWithString:[[displayItems objectAtIndex:indexPath.row] objectForKey:#"image"]];
NSLog(#"url to image share %#", url);
NSData *data = [[NSData alloc] initWithContentsOfURL:url];
NSLog(#"data to image share %#", data);
UIImage *tmpImage = [[UIImage alloc] initWithData:data];
NSLog(#"tmpImage to image share %#", tmpImage);
ydImage = tmpImage;
NSLog(#"ydimageview.image %#", ydImage);
// [NSThread detachNewThreadSelector:#selector(downloadAndLoadImage) toTarget:self withObject:nil];
[fbController setInitialText:#"Check out this link."];
[fbController addURL:[NSURL URLWithString:link]];
[fbController addImage:ydImage];
SLComposeViewControllerCompletionHandler __block completionHandler=^(SLComposeViewControllerResult result){
[fbController dismissViewControllerAnimated:YES completion:nil];
switch(result){
case SLComposeViewControllerResultCancelled:
default:
{
#ifdef DEBUG
NSLog(#"User Cancelled.");
#endif
[self removeSideSwipeView:YES];
}
break;
case SLComposeViewControllerResultDone:
{
#ifdef DEBUG
NSLog(#"Posted");
#endif
[self removeSideSwipeView:YES];
CustomAlertView *fbAlert = [[CustomAlertView alloc] initWithTitle:#"App Name" message:#"Facebook Post Successful!" delegate:nil cancelButtonTitle:#"Okay" otherButtonTitles:nil, nil];
[fbAlert show];
}
break;
}};
[fbController setCompletionHandler:completionHandler];
[self presentViewController:fbController animated:YES completion:nil];
}
looks like it might be an FB bug. sometimes they save to the albums sometimes not Unable to post image into facebook using SLComposeViewController?
Hi I have two UIButtons in an iOS app. One is to post to twitter the second is to post to Facebook. The facebook button works perfectly however the tweet is casing me some problems, the tweet sheet will open with the populated text, however it takes two taps of the cancel button to dismiss. If I tap on send the tweet will be sent and the sheet dismissed but my app freezes and becomes unresponsive. I have included both bits of code
- (IBAction)postTweet:(id)sender {
// if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]){
myTweet = [[SLComposeViewController alloc]init];
myTweet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
NSString *tweetString = [[NSString alloc]initWithFormat:#"%#\n%#\nvia #ValuatorApp", pdOne.text, pdTwo.text];
[myTweet setInitialText:tweetString];
[myTweet addURL:[NSURL URLWithString:#"http://sjb007.me/TheValuator"]];
[self presentViewController:myTweet animated:YES completion:nil];
// }
[myTweet setCompletionHandler:^(SLComposeViewControllerResult result) {
NSString *output = [[NSString alloc]init];
switch (result) {
case SLComposeViewControllerResultCancelled:
output = #"Twitter Post Cancelled";
break;
case SLComposeViewControllerResultDone:
output = #"Twitter post Succesful";
break;
default:
break;
}
NSLog(#"%#",output);
}];
}
- (IBAction)postFacebook:(id)sender {
// if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]){
myTweet = [[SLComposeViewController alloc]init];
myTweet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
if (pd3 != 0) {
NSString *facebookString = [[NSString alloc]initWithFormat:#"%#\n%#\n%#", pdOne.text,pdTwo.text, pdThree.text];
[myTweet setInitialText:facebookString];
}
else if (pd3 == 0){
NSString *facebookString = [[NSString alloc]initWithFormat:#"%#\n%#\n", pdOne.text,pdTwo.text];
[myTweet setInitialText:facebookString];
}
// [myTweet addImage:[UIImage imageNamed:#"Photo Jun 02, 22 46 37.jpg"]];
[myTweet addURL:[NSURL URLWithString:#"http://sjb007.me/TheValuator"]];
[self presentViewController:myTweet animated:YES completion:nil];
// }
[myTweet setCompletionHandler:^(SLComposeViewControllerResult result) {
NSString *output = [[NSString alloc]init];
switch (result) {
case SLComposeViewControllerResultCancelled:
output = #"Facebook Post Cancelled";
break;
case SLComposeViewControllerResultDone:
output = #"Facebook post Succesful";
break;
default:
break;
}
NSLog(#"%#",output);
}];
}
You are presenting the ViewController "myTweet"
[self presentViewController:myTweet animated:YES completion:nil];
but there is no dismiss... statement in your completionHandler
[self dismissViewControllerAnimated:YES completion:nil];