SLComposeViewController发布图像和url ios9
我正在尝试做的是,但它不起作用的是:使用内置的facebook共享器发布我选择的图片和facebook的url,问题是这两种方式都不起作用,要么图片+文本效果很好,要么url+文本效果很好,但是当我把它们组合在一起时,文本+图片+url会从url中得到图片,而不是我上传的图片。有什么建议吗?我在iOS9上做这件事SLComposeViewController发布图像和url ios9,ios,facebook,uiimage,share,slcomposeviewcontroller,Ios,Facebook,Uiimage,Share,Slcomposeviewcontroller,我正在尝试做的是,但它不起作用的是:使用内置的facebook共享器发布我选择的图片和facebook的url,问题是这两种方式都不起作用,要么图片+文本效果很好,要么url+文本效果很好,但是当我把它们组合在一起时,文本+图片+url会从url中得到图片,而不是我上传的图片。有什么建议吗?我在iOS9上做这件事 UIImage *tableViewScreenshot = [tblFeed screenshotOfCellAtIndexPath:idx]; SLCompose
UIImage *tableViewScreenshot = [tblFeed screenshotOfCellAtIndexPath:idx];
SLComposeViewController *fbSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[fbSheet setInitialText:@"I need your vote"];
[fbSheet addURL:[NSURL URLWithString:str]];
[fbSheet addImage:tableViewScreenshot];
当fb未安装时,我的ios应用程序中的facebook共享运行良好。我已经安装了fb来使用最新的api(4.7.x),现在共享根本不起作用。我检查是否拥有“发布\u操作”权限(在调用此方法之前,我已经“明确共享”了打开的图形设置、操作类型和功能。我正在验证内容(我没有收到错误)并且有一个委托,没有调用其任何方法
-(void)shareWithFacebook:(NSString *)message
{
if ([[FBSDKAccessToken currentAccessToken] hasGranted:@"publish_actions"])
{
NIDINFO(@"Facebook sharing has publish_actions permission");
}
else
{
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
[loginManager logInWithPublishPermissions:@[@"publish_actions"]
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
{
NIDERROR(@"Facebook sharing getting publish_actions permission failed: %@", error);
}
];
}
NSMutableDictionary *properties = [NSMutableDictionary dictionaryWithDictionary: @{
@"og:type": @"article",
@"og:title": @"Bloc",
@"og:description": message,
@"og:url": @"http://getonbloc.com/download"
}];
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];
// Create the action
FBSDKShareOpenGraphAction *action = [FBSDKShareOpenGraphAction actionWithType:@"mynamespace:Share" object:object key:@"article"];
[action setString:@"true" forKey:@"fb:explicitly_shared"];
// Create the content
FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
content.action = action;
content.previewPropertyName = @"article";
// Share the content
FBSDKShareAPI *shareAPI = [[FBSDKShareAPI alloc] init];
shareAPI.shareContent = content;
shareAPI.delegate = self;
NSError *error;
if([shareAPI validateWithError:&error] == NO)
{
NIDERROR(@"Facebook sharing content failed: %@", error);
}
[shareAPI share];
}
#pragma mark - FBSDKSharingDelegate
- (void) sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results
{
NIDINFO(@"Facebook sharing completed: %@", results);
}
- (void) sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error
{
NIDERROR(@"Facebook sharing failed: %@", error);
}
- (void) sharerDidCancel:(id<FBSDKSharing>)sharer
{
NIDINFO(@"Facebook sharing cancelled.");
}
-(void)与Facebook共享:(NSString*)消息
{
如果([[FBSDKAccessToken currentAccessToken]已授予:@“发布操作”])
{
NIDINFO(@“Facebook共享具有发布操作权限”);
}
其他的
{
FBSDKLoginManager*loginManager=[[FBSDKLoginManager alloc]init];
[loginManager logInWithPublishPermissions:@[@“发布操作”]
处理程序:^(FBSDKLoginManagerLoginResult*结果,NSError*错误)
{
NIDERROR(@“Facebook共享获取发布操作权限失败:%@”,错误);
}
];
}
NSMutableDictionary*属性=[NSMutableDictionary Dictionary WithDictionary:@{
@“og:类型”:@“文章”,
@“og:标题”:@“集团”,
@“og:描述”:消息,
@“og:url”:@”http://getonbloc.com/download"
}];
FBSDKSharePengraphObject*对象=[FBSDKSharePengraphObject对象WithProperties:properties];
//创建操作
FBSDKSharePengraphAction*action=[FBSDKSharePengraphAction actionWithType:@“mynamespace:Share”对象:对象键:@“article”];
[action setString:@“true”forKey:@“fb:显式共享”];
//创建内容
FBSDKShareOpenGraphContent*内容=[[FBSDKShareOpenGraphContent alloc]init];
内容.行动=行动;
content.previewPropertyName=@“文章”;
//分享内容
FBSDKShareAPI*shareAPI=[[FBSDKShareAPI alloc]init];
shareAPI.shareContent=内容;
shareAPI.delegate=self;
n错误*错误;
if([shareAPI validateWithError:&错误]==否)
{
NIDERROR(@“Facebook共享内容失败:%@”,错误);
}
[共享API共享];
}
#pragma标记-FBSDKSharingDelegate
-(void)sharer:(id)sharer未完成结果:(NSDictionary*)结果
{
NIDINFO(@“Facebook共享完成:%@”,结果);
}
-(无效)共享者:(id)共享者错误:(N错误*)错误
{
NIDERROR(@“Facebook共享失败:%@”,错误);
}
-(作废)SharerDicCancel:(id)sharer
{
NIDINFO(@“Facebook共享已取消”);
}
问题在于Facebook更改了一些策略,因此默认情况下无法显示文本或图像。这就是为什么您看不到文本和照片的原因。这里有两种情况,一种是安装了Facebook应用程序,另一种是未安装Facebook应用程序。下面一种是当Facebook应用程序已安装在装置。
而这一次是当设备上没有安装Facebook应用程序时
这是我的代码:
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller addURL:[NSURL URLWithString:@"https://www.google.com"]];
[controller addImage:[UIImage imageNamed:@"icon_circle"]];
[controller setInitialText:@"Bhavuk you're great!"];
[self presentViewController:controller animated:YES completion:nil];
因此,如果你想共享所有内容,最好使用FB SDK。因此目前似乎没有解决方案,我们应该找到解决办法,可能先将所有内容上传到url,然后使用FB SDK指向该url中的图片+链接作为离线图片,不幸的是,这似乎不起作用。总之,即使在iOS 10上,这个问题仍然存在。一个简单的解决方法就是删除URL,例如:
SLComposeViewController *fbSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[fbSheet setInitialText:@"I need your vote"];
[fbSheet addImage:tableViewScreenshot];
这不是对OP的直接回答,但如果您只关心在共享内容时显示文本和图像,那么这里有一个可能的解决方案: 如果要在SlComposeView中显示的图像和文本与要共享的网站中的信息相同,则根本不需要在iOS端执行任何特殊操作 如果您也是创建了共享URL的网页的人,如果您在该网页上有适当的Open Graph META标记,则Facebook类型的SLComposeView将自动显示在应用程序内的网页上设置的图像和文本
有关Facebook开放图形标记的一些信息,请参见没有ios9问题。FB最新api(4.7.x)问题您甚至无法添加initialText。它不会出现。