【发布时间】:2016-10-07 06:51:51
【问题描述】:
我想在我的自定义按钮点击后分享照片,我可以分享链接和消息,但在分享照片时却无法做到。
我正在使用最新的 Facebook SDK 框架 (4.15.1)。
这是我在按钮点击中的代码。
- (IBAction)btnsharecustom:(id)sender {
//Get aws s3 Image.
NSString* strS3ImageURL = @"https://TEST_IMAGE_URL/1473497380077.jpg";
//Convert to URL.
NSURL* url1 = [NSURL URLWithString:strS3ImageURL];
//Convert it into data.
NSData* data = [NSData dataWithContentsOfURL:url1];
//Convert it to image.
UIImage* image = [UIImage imageWithData:data];
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc]init];
photo.image = image;
photo.caption = @"Test Caption";
photo.userGenerated = YES;
FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
content.photos = @[photo];
}
我将此代码包含在应用程序委托中。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
return YES;
}
//FaceBook URLs.
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
BOOL handled = [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation
];
// Add any custom logic here.
return handled;
}
在 info.plist 中也包含此代码
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fb15771408xxx409xx</string>
</array>
</dict>
<key>FacebookAppID</key>
<string>15771408xxx409xx</string>
<key>FacebookDisplayName</key>
<string>Cedar iOS</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
<string>fbapi20130214</string>
<string>fbapi20130410</string>
<string>fbapi20130702</string>
<string>fbapi20131010</string>
<string>fbapi20131219</string>
<string>fbapi20140410</string>
<string>fbapi20140116</string>
<string>fbapi20150313</string>
<string>fbapi20150629</string>
<string>fbapi20160328</string>
<string>fbauth</string>
<string>fb-messenger-api20140430</string>
</array>
当我点击我的自定义按钮 Facebook 应用程序或 safari 浏览器未启动时,谁能告诉我这里缺少什么?
【问题讨论】:
-
FBSDKSharePhotoContent 仅适用于 FB 应用程序...所以请确保您拥有应用程序并已登录。
-
@SanketBhavsar 是的,我已经安装了 FB 应用程序并且也登录了。
-
确保您已通过您的应用程序登录到 facebook 并授予在 facebook 上分享内容的权限。如果你想要代码,那么我会发布我的代码。
-
如果没有安装Facebook App,如何通过浏览器分享?
标签: ios objective-c iphone facebook-graph-api fbsdksharekit