我想在FBLinkShareParams上发布名称,linkDescription和图片,但是在Facebook应用安装条件下无法做到这一点,但是在FBWebDialogs中完成时在Facebook应用未安装条件下可以正常工作。我只能在Facebook应用安装状态下发布params.link。
我使用了如下所示的代码:
#pragma mark - facebook share
//facebook share
- (void)shareLinkinFB{
/* Facebook app is installed*/
FBLinkShareParams *params = [[FBLinkShareParams alloc] init];
params.link = [NSURL URLWithString:@"https://developers.facebook.com/docs/ios/share/"];
params.name= @"Dieheart";
params.picture= [NSURL URLWithString:Str_KoolkatPic];
params.linkDescription=@"A quick and better way to get anything delivered at your doorstep. ";
// If the Facebook app is installed and we can present the share dialog
if ([FBDialogs canPresentShareDialogWithParams:params]) {
[FBDialogs presentShareDialogWithLink:params.link handler:^(FBAppCall *call, NSDictionary *results, NSError *error) { if(error) {
// An error occurred, we need to handle the error
NSLog(@"Error publishing story: %@", error.description);
} else {
// Success
NSLog(@"result %@", results);
}
}];
NSLog(@"Share login page Now");
} else {
/* Facebook app Not installed*/
NSLog(@"Share dialog");
NSString *urlString = [NSString stringWithFormat:@"%@/resources/images/login-logo.png",SERVER_ADDRESS];
NSString *Str_NameLabel;
NSString *Str_Description;
Str_NameLabel=@"testing for idelivery IOS application";
Str_Description=@"Share functionality in progress";
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
Str_NameLabel, @"name",
@"idelivery Town center", @"caption",
Str_Description, @"description",
@"https://www.facebook.com/edeliveryksa", @"link",
urlString, @"picture",
nil];
// Show the feed dialog
[FBWebDialogs presentFeedDialogModallyWithSession:nil parameters:params
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 cancelled.
NSLog(@"User cancelled.");
} else {
// Handle the publish feed callback
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
if (![urlParams valueForKey:@"post_id"]) {
// User cancelled.
NSLog(@"User cancelled.");
} else {
// User clicked the Share button
NSString *result = [NSString stringWithFormat: @"Posted story, id: %@", [urlParams valueForKey:@"post_id"]];
NSLog(@"result %@", result);
[self postSuccess]; // success vako condn ko lagi banako
}
}
}
}];
}}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
BOOL urlWasHandled = [FBAppCall handleOpenURL:url
sourceApplication:sourceApplication
fallbackHandler:^(FBAppCall *call) {
NSLog(@"Unhandled deep link: %@", url);
// Here goes the code to handle the links
}];
return urlWasHandled;
}
// A function for parsing URL parameters returned by the Feed Dialog.
- (NSDictionary*)parseURLParams:(NSString *)query {
NSArray *pairs = [query componentsSeparatedByString:@"&"];
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
for (NSString *pair in pairs) {
NSArray *kv = [pair componentsSeparatedByString:@"="];
NSString *val =
[kv[1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
params[kv[0]] = val;
}
return params;
}
- (void)postSuccess{
NSLog(@" post success");
}
希望任何人都能帮助我
最佳答案
看起来您在用真实的参数调用canPresentShareDialogWithParams:
,但是当涉及到实际显示对话框时,您在使用nil
链接进行调用,这可能就是为什么什么都没显示出来的原因。
您应该使用创建的参数调用presentShareDialogWithParams:clientState:handler:
方法。
[FBDialogs presentShareDialogWithParams:params
clientState:nil
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {...}];
关于ios - 在Facebook共享中,我无法在Facebook应用安装状态下的FBLinkShareParams上发布名称,linkDescription和图片,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30505896/