我正在向Facebook friend 发送应用程序请求,因此如何在UIWebView中打开应用程序请求?

NSDictionary * parametersDict = @ {@“至”:@“”};

        [FBWebDialogs presentRequestsDialogModallyWithSession:FBSession.activeSession
                                                      message:@"YouPin"
                                                        title:@"my title"
                                                   parameters:parametersDict
                                                      handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
         {
             if(error)
             {
                 NSLog(@"Some errorr: %@", [error description]);
                 UIAlertView *alrt = [[UIAlertView alloc] initWithTitle:@"Invitiation Sending Failed" message:@"Unable to send inviation at this Moment, please make sure your are connected with internet" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
                 [alrt show];
             }
             else
             {
                 if (![resultURL query])
                 {
                     [self.navigationController popViewControllerAnimated:YES];
                     return;
                 }

                 NSDictionary *paramsStr = [self parseURLParamsSecond:[resultURL query]];
                 NSMutableArray *recipientIDs = [[NSMutableArray alloc] init];
                 for (NSString *paramKey in paramsStr)
                 {
                     if ([paramKey hasPrefix:@"to["])
                     {
                         [recipientIDs addObject:[paramsStr objectForKey:paramKey]];
                     }
                 }
                 if ([paramsStr objectForKey:@"request"])
                 {
                     NSLog(@"Request ID: %@", [paramsStr objectForKey:@"request"]);
                 }
                 if ([recipientIDs count] > 0)
                 {
                     NSLog(@"Recipient ID(s): %@", recipientIDs);
                     UIAlertView *alrt = [[UIAlertView alloc] initWithTitle:@"Success!" message:@"Invitation(s) sent successfuly!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
                     alrt.tag = 10;
                     [alrt show];
                 }
             }
         }friendCache:nil];

    - (NSDictionary *)parseURLParamsSecond:(NSString *)query
    {
        NSArray *pairs = [query componentsSeparatedByString:@"&"];
        NSMutableDictionary *paramsSECOND = [[NSMutableDictionary alloc] init];
        for (NSString *pair in pairs)
        {
            NSArray *kv = [pair componentsSeparatedByString:@"="];

            [paramsSECOND setObject:[[kv objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
                             forKey:[[kv objectAtIndex:0] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        }

        return paramsSECOND;
    }

我正在向Facebook friend 发送应用程序请求,因此如何在UIWebView中打开应用程序请求?

最佳答案

为了邀请用户,您可以在添加facebook-sdk之后使用以下代码

[FBWebDialogs
 presentRequestsDialogModallyWithSession:nil
message:@"Your invite message"
title:nil
parameters:nil
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
                                      if (error) {
                                          // An error occurred, we need to handle the error
                                          // See: https://developers.facebook.com/docs/ios/errors
                                          NSLog(@"Error publishing story: %@", error.description);
                                      } else {
                                          if (result == FBWebDialogResultDialogNotCompleted) {
                                              // User canceled.
                                              NSLog(@"User cancelled.");
                                          } else {
                                              // Handle the publish feed callback




                                              }

                                    }


}];

/////////////////////////

在webview中显示应用程序请求:发送 friend 的facebookId和您的消息。
- (void)sendAppRequestToFacebookFriend:(NSString*)message andFacebookId:(NSString*)friendFBId {


NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                message, @"message",
                               @"", @"redirect_url",
                               friendFBId,@"to",
                               nil];


[FBWebDialogs
 presentRequestsDialogModallyWithSession:nil
 message:message
 title:@"App Title App"
 parameters:params
 handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {

     if (!error) {


         if (result == FBWebDialogResultDialogNotCompleted) {





         }
         else if([[resultURL description] hasPrefix:@"fbconnect://success?request="]) {
             //code after success
            }

     }

 }
  ];

}

关于ios - iOS8-Facebook SDK-如何使用UIWebView打开应用程序请求网址,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28451041/

10-11 00:09