簡體   English   中英

iOS Facebook SDK 4.0共享圖像

[英]iOS Facebook sdk 4.0 share an image

我正在嘗試使用新的facebook sdk 4.0共享圖像。 我在facebook示例中使用了相同的代碼,但是在嘗試顯示FBSDKShareDialog時遇到了此異常。

*由於未捕獲的異常'NSInvalidArgumentException'而終止應用程序,原因:'無法解析格式字符串“ SELF NOT NULL”'*首先拋出調用棧:(0 CoreFoundation 0x000000010b782a75 __exceptionPreprocess + 165 1 libobjc.A.dylib
0x000000010b35abb7 objc_exception_throw + 45 2基礎
0x000000010aca097d _qfqp2_perform解析+ 8495 3基礎
0x000000010ac9e7e6 + [NSPredicate predicateWithFormat:arguments:] + 46 4基礎0x000000010ac9e7a0 + [NSPredicate predicateWithFormat:] + 142 5 PhotoGunShot 0x0000000107f1a4fc-[FBSDKShareDialog _showShareSheetWithFShowShow7B 0653]

這是代碼

- (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];
}

首先,我創建一個顯示共享選項的UIAlertController,並添加相對的UIAlertAction ,當我調用共享對話框時會生成異常。
有什么建議嗎?

此問題將在下一個SDK版本中修復。

顯然,您可以從FBSDKShareDialog中刪除以下行,並從源代碼構建框架以解決該問題。 https://github.com/facebook/facebook-ios-sdk/blob/master/FBSDKShareKit/FBSDKShareKit/FBSDKShareDialog.m#L442

您可以在此處查看Andrea提交的錯誤: https : //developers.facebook.com/bugs/964300063610778/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM