Building an iOS app for reading articles. I’m using Facebook SDK to share the article link and image on Facebook.
This is the process:
After clicking on bar button item on top right, UIActivityViewController gets opened on the bottom of the screen which gives option to share via fb, google , linked in etc.
On clicking the Facebook button in UIActivityVIewController, default screen opens for sharing but ideally fb SDK code should get executed.
The following "if condition” does not executed.
[AVC setCompletionHandler:^(NSString *activityType, BOOL completed)
{
if([activityType isEqualToString: UIActivityTypePostToFacebook]){
FBLinkShareParams *params = [[FBLinkShareParams alloc] init];
- But when clicked on the cancel button of the default screen, “if condition" gets executed and app is able to share the article as expected.
Here is the code.
- (IBAction)ysshareAction:(id)sender {
NSURL *Imageurl = [NSURL URLWithString:_DetailModal1[2]];
NSData *data = [NSData dataWithContentsOfURL:Imageurl];
UIImage *image = [[UIImage alloc] initWithData:data];
NSURL *linkURL = [NSURL URLWithString:_DetailModal1[4]];
NSMutableAttributedString *stringText = [[NSMutableAttributedString alloc] initWithString:_DetailModal1[0]];
[stringText addAttribute:NSLinkAttributeName value:linkURL range:NSMakeRange(0, stringText.length)];
NSArray *itemArrany = @[stringText,image,];
UIActivityViewController *AVC = [[UIActivityViewController alloc] initWithActivityItems:itemArrany applicationActivities:nil];
AVC.excludedActivityTypes=@[];
[AVC setCompletionHandler:^(NSString *activityType, BOOL completed)
{
if([activityType isEqualToString: UIActivityTypePostToFacebook]){
FBLinkShareParams *params = [[FBLinkShareParams alloc] init];
params.link = [NSURL URLWithString:@"https://www.youtube.com/watch?v=pa8lsBNG31c"];
if ([FBDialogs canPresentShareDialogWithParams:params]) {
[FBDialogs presentShareDialogWithLink:params.link
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
NSLog(@"Error publishing story: %@", error.description);
} else {
NSLog(@"result %@", results);
}
}];
} else {
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"YourStory", @"name",
_DetailModal1[0], @"caption",
_DetailModal1[4], @"link",
_DetailModal1[2], @"picture",
nil];
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
NSLog(@"Error publishing story: %@", error.description);
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
NSLog(@"User cancelled.");
} else {
NSLog(@"User cancelled.");
}
}
}];
}
}
}];
[self presentViewController:AVC animated:YES completion:nil];
}
Any help is really appreciated.