簡體   English   中英

ios8- Facebook sdk-如何使用UIWebView打開應用程序請求URL

[英]ios8- Facebook sdk-how to open app request url using UIWebView

我正在向facebook的朋友發送應用程序請求,那么我如何在UIWebView中打開應用程序請求?

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

        [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的朋友發送應用程序請求,那么我如何在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中顯示應用程序請求:發送您朋友的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
            } 

     } 

 }
  ];

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM