Facebook deep linking with iOS app

后端 未结 2 1748
死守一世寂寞
死守一世寂寞 2020-12-19 13:39

I am using below code to post to Facebook. It is working perfectly but when i replace MY_URL with myapp://test_page// the post won\'t appea

2条回答
  •  清歌不尽
    2020-12-19 14:15

    Thanks for answer @Jai Govindani, but it was much simpler than your answer. I found out this from Facebook documentations.

    First i changes App settings in Facebook account:

    enter image description here

    I added Bundle identifier in app's settings. And enabled Facebook deep linking And of course, i also needed "App store ID"

    And wrote the below method with completionBlock -

    - (void)shareOnFacebookWithName:(NSString *)strName withDescription:(NSString *)strDesc withLink:(NSString *)strLink WithPictureLink:(NSString *)strPicLink withCaption:(NSString *)strCaption withCompletionBlock:(shareCompletion)completionBlock
    {
        __block NSString *strLinkBlock = strLink;
    
        [FBSession openActiveSessionWithPublishPermissions: [NSArray arrayWithObjects: @"publish_stream", nil] defaultAudience: FBSessionDefaultAudienceEveryone allowLoginUI:YES completionHandler: ^(FBSession *session,FBSessionState status,NSError *error)
         {
             if (error)
             {
                 completionBlock(NO);
                 return;
    
                 NSLog(@"error");
             }
             else
             {
                 [FBSession setActiveSession:session];
                 NSLog(@"LOGIN SUCCESS");
    
                 // Put together the dialog parameters
    
                 NSArray* actionLinks = [NSArray arrayWithObjects:
                                         [NSDictionary dictionaryWithObjectsAndKeys:
                                          @"Scisser",@"name",
                                          @"http://m.facebook.com/apps/uniquenamespace/",@"link",
                                          nil],
                                         nil];
    
                 NSString *actionLinksStr = [actionLinks JSONRepresentation];
    
                 if (strLink.length == 0)
                 {
                     strLinkBlock = @"http://www.scisser.com";
                 }
    
                 NSString *strDescription = strDesc;
                 if (!strDescription)
                 {
                     strDescription = @"";
                 }
    
                 NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                                strName, @"name",
                                                strCaption, @"caption",
                                                strDescription, @"description",
                                                strLinkBlock, @"link",
                                                strPicLink, @"picture",
                                                @"foo", @"ref",
                                                actionLinksStr, @"actions",
                                                nil];
    
                 // Make the request
                 [FBRequestConnection startWithGraphPath:@"/me/feed"
                                              parameters:params
                                              HTTPMethod:@"POST"
                                       completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                                           if (!error)
                                           {
                                               // Link posted successfully to Facebook
    
                                               [self alertshowWithTitle:@"Congratulations" message:@"Post was successfully shared on your Facebook timeline."];
    
                                               NSLog(@"%@",[NSString stringWithFormat:@"result: %@", result]);
    
                                               completionBlock(YES);
                                               return;
                                           }
                                           else
                                           {
                                               // An error occurred, we need to handle the error
                                               // See: https://developers.facebook.com/docs/ios/errors
                                               NSLog(@"%@",[NSString stringWithFormat:@"%@", error.description]);
    
                                               completionBlock(NO);
                                               return;
                                           }
                                       }];
    
             }
         }];
    }
    

提交回复
热议问题