Skip to content

Instantly share code, notes, and snippets.

@SongJiaqiang
Last active October 19, 2016 06:38
Show Gist options
  • Save SongJiaqiang/562b96ff1de6fe4b2c0ec4db2f1c3a89 to your computer and use it in GitHub Desktop.
Save SongJiaqiang/562b96ff1de6fe4b2c0ec4db2f1c3a89 to your computer and use it in GitHub Desktop.
Share video to facebook with FB SDK v4.16
@implementation ShareTool
+ (void)shareVideoToFacebookWithVideoURL:(NSURL *)videoAssetLibraryURL fromViewController:(UIViewController *)viewController {
if (![[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fb://"]]) {
[ShareTool showAlertDialogWithTitle:@"NOTICE" andMessage:@"You Did Not Install Facebook" fromViewController:viewController];
break;
}
FBSDKShareVideo *fbVideo = [[FBSDKShareVideo alloc] init];
FBSDKShareVideoContent *fbVideoContent = [[FBSDKShareVideoContent alloc] init];
fbVideo.videoURL = videoAssetLibraryURL;
fbVideoContent.video = fbVideo;
UIImage *previewImage = [UIImage imageNamed:@""];
fbVideoContent.previewPhoto = [FBSDKSharePhoto photoWithImage:previewImage userGenerated:YES];
FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init];
// default mode is FBSDKShareDialogModeAutomatic
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fbauth2://"]]){
dialog.mode = FBSDKShareDialogModeNative;
} else {
dialog.mode = FBSDKShareDialogModeBrowser;
}
dialog.shareContent = fbVideoContent;
dialog.delegate = self;
dialog.fromViewController = self;
[dialog show];
}
+ (void)showAlertDialogWithTitle:(NSString *)title andMessage:(NSString *)message fromViewController:(UIViewController *)viewController {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];
[viewController presentViewController:alertController animated:YES completion:nil];
}
@end
@SongJiaqiang
Copy link
Author

不知道是怎么回事,分享事件有时候会失效,控制台打印"PBItemCollectionServicer connection disconnect"错误,Google之后并没有多少关于PBItemCollectionServicer这个关键词的结果,现在只知道这是一个iOS Runtime Service,到底哪里出了问题?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment