I'm trying to share an image using the new 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
.
* 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
0x000000010b35abb7 objc_exception_throw + 45 2 Foundation
0x000000010aca097d _qfqp2_performParsing + 8495 3 Foundation
0x000000010ac9e7e6 +[NSPredicate predicateWithFormat:arguments:] + 46 4 Foundation 0x000000010ac9e7a0 +[NSPredicate predicateWithFormat:] + 142 5 PhotoGunShot 0x0000000107f1a4fc -[FBSDKShareDialog _showShareSheetWithCanShowError:validationError:] + 653 6 PhotoGunShot 0x0000000107f18f7b -[FBSDKShareDialog show] + 147
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.
Any suggestion?
Aucun commentaire:
Enregistrer un commentaire