简体   繁体   English

iOS Facebook SDK 4.0共享图像

[英]iOS Facebook sdk 4.0 share an image

I'm trying to share an image using the new facebook sdk 4.0. 我正在尝试使用新的facebook sdk 4.0共享图像。 I'm using the same code in the facebook example but I'm getting this exception when I try to present the FBSDKShareDialog . 我在facebook示例中使用了相同的代码,但是在尝试显示FBSDKShareDialog时遇到了此异常。

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "SELF NOT NULL"' * First throw call stack: ( 0 CoreFoundation 0x000000010b782a75 __exceptionPreprocess + 165 1 libobjc.A.dylib *由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'无法解析格式字符串“ SELF NOT NULL”'*首先抛出调用栈:(0 CoreFoundation 0x000000010b782a75 __exceptionPreprocess + 165 1 libobjc.A.dylib
0x000000010b35abb7 objc_exception_throw + 45 2 Foundation 0x000000010b35abb7 objc_exception_throw + 45 2基础
0x000000010aca097d _qfqp2_performParsing + 8495 3 Foundation 0x000000010aca097d _qfqp2_perform解析+ 8495 3基础
0x000000010ac9e7e6 +[NSPredicate predicateWithFormat:arguments:] + 46 4 Foundation 0x000000010ac9e7a0 +[NSPredicate predicateWithFormat:] + 142 5 PhotoGunShot 0x0000000107f1a4fc -[FBSDKShareDialog _showShareSheetWithCanShowError:validationError:] + 653 6 PhotoGunShot 0x0000000107f18f7b -[FBSDKShareDialog show] + 147 0x000000010ac9e7e6 + [NSPredicate predicateWithFormat:arguments:] + 46 4基础0x000000010ac9e7a0 + [NSPredicate predicateWithFormat:] + 142 5 PhotoGunShot 0x0000000107f1a4fc-[FBSDKShareDialog _showShareSheetWithFShowShow7B 0653]

Here is the code 这是代码

- (UIAlertAction*) createActionForFacebookWithMediaPath:(NSString*) path andMediaType:(MediaType) mediaType {
    NSString * mediaName = mediaType == kMediaTypeImage ? NSLocalizedString(@"KEY_IMAGE", nil) : NSLocalizedString(@"KEY_VIDEO", nil);
    UIAlertAction* facebookAction = [UIAlertAction actionWithTitle:[NSString stringWithFormat:@"%@ %@",NSLocalizedString(@"KEY_SHARE_YOUR", nil),mediaName] style:UIAlertActionStyleDefault
                                                          handler:^(UIAlertAction * action) {
                                                              NSObject<FBSDKSharingContent> * content = nil;
                                                              if (mediaType == kMediaTypeImage) {
                                                                  NSURL * fileURL = [NSURL URLWithString:path];
                                                                  FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
                                                                  photo.imageURL = fileURL;
//                                                                  photo.userGenerated = YES;
                                                                  FBSDKSharePhotoContent * photoContent = [[FBSDKSharePhotoContent alloc] init];
                                                                  photoContent.photos = @[photo];
                                                                  content = photoContent;
                                                              }
                                                              else if (mediaType == kMediaTypeVideo) {
                                                                  NSURL *videoURL = [NSURL fileURLWithPath:path];

                                                                  FBSDKShareVideo *video = [[FBSDKShareVideo alloc] init];
                                                                  video.videoURL = videoURL;
                                                                  FBSDKShareVideoContent * videoContent = [[FBSDKShareVideoContent alloc] init];
                                                                  videoContent.video = video;
                                                                  content = videoContent;
                                                              }
                                                                  [FBSDKShareDialog showFromViewController:self
                                                                                               withContent:content
                                                                                                  delegate:nil];

                                                          }];
    return facebookAction;

}
- (UIAlertAction*) createActionForCameraRollWithMediaPath:(NSString*) path andMediaType:(MediaType) mediaType {
    return nil;

}
- (void) showShareOptionsForMediaPath:(NSString*)path {
    UIAlertController * alertControl =[UIAlertController alertControllerWithTitle:NSLocalizedString(@"KEY_SHARE_TITLE", nil) message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"KEY_CANCEL", nil) style:UIAlertActionStyleCancel handler:NULL];
    [alertControl addAction:cancelAction];
    MediaType mediaType = [self checkMediaTypeAtPath:path];
    switch (mediaType) {
        case kMediaTypeImage:
        {
            UIAlertAction * fbAction =[self createActionForFacebookWithMediaPath:path andMediaType:kMediaTypeImage];
            [alertControl addAction:fbAction];
        }
            break;
        case kMediaTypeVideo:
        {
            UIAlertAction * fbAction =[self createActionForFacebookWithMediaPath:path andMediaType:kMediaTypeVideo];
            [alertControl addAction:fbAction];

        }
            break;
        case kMediaTypeUnknown:
        {
            //EXCEPTION
        }
            break;
        default:
            break;
    }

    [self presentViewController:alertControl animated:YES completion:nil];
}

First I create an UIAlertController that shows the share options, and add the relative UIAlertAction , the exception is generated when I call the share dialog. 首先,我创建一个显示共享选项的UIAlertController,并添加相对的UIAlertAction ,当我调用共享对话框时会生成异常。
Any suggestion? 有什么建议吗?

This issue will be fixed in the next SDK release. 此问题将在下一个SDK版本中修复。

Apparently you can remove the below line from FBSDKShareDialog and build the framework from source to work around it. 显然,您可以从FBSDKShareDialog中删除以下行,并从源代码构建框架以解决该问题。 https://github.com/facebook/facebook-ios-sdk/blob/master/FBSDKShareKit/FBSDKShareKit/FBSDKShareDialog.m#L442 https://github.com/facebook/facebook-ios-sdk/blob/master/FBSDKShareKit/FBSDKShareKit/FBSDKShareDialog.m#L442

You can view the bug that Andrea filed , here : https://developers.facebook.com/bugs/964300063610778/ 您可以在此处查看Andrea提交的错误: https : //developers.facebook.com/bugs/964300063610778/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM