我正在尝试为我的ios应用创建一个简单的共享功能。我想利用新的共享对话框(诸如标记朋友,添加地点,ecc等优点)。我想分享的是一张照片,一个指向itunes app下载的链接,一个来自ios应用程序的描述。我尝试过这样的共享方式:
NSURL *url=[[NSURL alloc] initWithString:@"https://itunes.apple.com/it/app/myapplication"];
[FBDialogs presentShareDialogWithLink:url name:@"My app name" caption:@"" description:@"prefilled descriptiontest" picture:[NSURL URLWithString:@"http://www.example.com/image.jpg"] clientState:nil handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
UIAlertView *av = [[[UIAlertView alloc]
initWithTitle:@"Sorry :("
message:@"There's been a problem publishing your message. Please try again!"
delegate:self
cancelButtonTitle:@"Close"
otherButtonTitles:nil] autorelease];
[av show];
} else {
// Success
UIAlertView *av = [[[UIAlertView alloc]
initWithTitle:@"Published!"
message:@"Your post has been successfully published."
delegate:self
cancelButtonTitle:@"Close"
otherButtonTitles:nil] autorelease];
[av show];
}
}];
它有效,但我只在分享对话框中看到我的预填充描述,当我在facebook上看到共享内容时,我只看到从链接页面中获取的描述。所以我尝试了另一个解决方案,即photodialog:
UIImage *Image=[UIImage imageNamed:@"myphoto.jpg"];
// Open the image picker and set this class as the delegate
FBPhotoParams *params = [[FBPhotoParams alloc] init];
// Note that params.photos can be an array of images. In this example
// we only use a single image, wrapped in an array.
params.photos = @[Image];
[FBDialogs presentShareDialogWithPhotoParams:params
clientState:nil
handler:^(FBAppCall *call,
NSDictionary *results,
NSError *error) {
if (error) {
NSLog(@"Error: %@",
error.description);
} else {
NSLog(@"Success!");
}
}];
通过这种方式,我可以在我的墙上发布照片,但描述参数似乎只是读取,我无法设置任何预填充文本。我该怎么办?有一种方法可以在sharelink对话框中强制显示我的描述文本吗?或者有一种在photodialog中设置文本的方法?还是有其他解决方案?
答案 0 :(得分:0)
唯一的解决方案似乎是仅使用网络回退:
NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithObjectsAndKeys:
name, @"name",
author, @"caption",
linkShare, @"link",
userImage, @"picture",
nil];
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:parameter
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error)
{
NSLog(@"Error publishing story: %@", error.description);
}
else
{
if (result == FBWebDialogResultDialogNotCompleted)
{
NSLog(@"User cancelled.");
}
else
{
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
NSLog(@"User login");
if (![urlParams valueForKey:@"post_id"])
{
NSLog(@"User cancelled post.");
}
else
{
NSString *result = [NSString stringWithFormat: @"Posted story, id: %@", [urlParams valueForKey:@"post_id"]];
NSLog(@"result %@", result);
}
}
}
}];