Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FBSDKShareVideo failed, Error Message:"FBSDKErrorDeveloperMessageKey=Must refer to an asset file." #2396

Open
5 tasks done
pepperchili opened this issue Apr 22, 2024 · 1 comment

Comments

@pepperchili
Copy link

Checklist before submitting a bug report

Xcode version

15.0

Facebook iOS SDK version

17.0.0

Dependency Manager

CocoaPods

SDK Framework

Share

Goals

can realize sharing video function

Expected results

can realize sharing video function

Actual results

rinting description of error:
Error Domain=com.facebook.sdk.share Code=2 "(null)" UserInfo={com.facebook.sdk:FBSDKErrorArgumentNameKey=videoURL, com.facebook.sdk:FBSDKErrorArgumentValueKey=file:///private/var/containers/Bundle/Application/6C33A060-062A-431F-BE09-6D77DBC603CA/EfunKrDemo.app/shareMedia.mp4, com.facebook.sdk:FBSDKErrorDeveloperMessageKey=Must refer to an asset file.}

Steps to reproduce

No response

Code samples & details

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"shareMedia" ofType:@"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filePath];
FBSDKShareVideo *vedio = [[FBSDKShareVideo alloc] initWithVideoURL:fileURL previewPhoto:nil];

FBSDKShareVideoContent *vc = [[FBSDKShareVideoContent alloc] init];
vc.video = vedio;
FBSDKShareDialog *dialog = [FBSDKShareDialog dialogWithViewController:self withContent:vc delegate:self];
dialog.mode = FBSDKShareDialogModeNative;
[dialog show];
// shareMedia.mp4 is a local video file imported into my project.
@pepperchili
Copy link
Author

We've attempted to use the Photos framework to obtain a PHAsset and it works. However, it requires manually creating the user interface, which is not our preference.

PHFetchOptions *options = [[PHFetchOptions alloc] init];
options.predicate = [NSPredicate predicateWithFormat:@"mediaType = %d", PHAssetMediaTypeVideo];
PHFetchResult *assetsFetchResult = [PHAsset fetchAssetsWithOptions:options];
[assetsFetchResult enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
    PHAsset *asset = (PHAsset *)obj;
}];

We prefer to use PHPickerViewController. Unfortunately, it doesn't seem to work as expected. Instead of receiving a PHAsset type, we only obtained a file URL. The same error as mentioned below occurred: "FBSDKErrorDeveloperMessageKey=Must refer to an asset file".

PHPickerConfiguration *configuration = [[PHPickerConfiguration alloc] initWithPhotoLibrary:[PHPhotoLibrary sharedPhotoLibrary]];
configuration.selectionLimit = 1;
configuration.filter = [PHPickerFilter videosFilter];
PHPickerViewController *picker = [[PHPickerViewController alloc] initWithConfiguration:configuration];
if (@available(iOS 14, *)) {
    picker.delegate = self;
} else {
    // Fallback on earlier versions
}
[self presentViewController:picker animated:YES completion:nil];

//delegate
- (void)picker:(PHPickerViewController *)picker didFinishPicking:(NSArray<PHPickerResult *> *)results {
    [picker dismissViewControllerAnimated:YES completion:nil];

    for (PHPickerResult *result in results) {
        if (@available(iOS 14, *)) {
            NSItemProvider *itemProvider = result.itemProvider;
            NSString *assetIdentifier = result.assetIdentifier;
            [itemProvider loadFileRepresentationForTypeIdentifier:@"public.movie" completionHandler:^(NSURL * _Nullable url, NSError * _Nullable error) {
                NSLog(@"Selected video URL: %@", url);
                dispatch_async(dispatch_get_main_queue(), ^{
                    FBSDKShareVideo *vedio = [[FBSDKShareVideo alloc] initWithVideoURL:url previewPhoto:nil];
                    FBSDKShareVideoContent *vc = [[FBSDKShareVideoContent alloc] init];
                    vc.video = vedio;
                    
                    FBSDKShareDialog *dialog = [FBSDKShareDialog dialogWithViewController:self withContent:vc delegate:self];
                    dialog.mode = FBSDKShareDialogModeNative;
                    [dialog show];
                });
     
            }];
        } else {
            // Fallback on earlier versions
        }
    }
}

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

No branches or pull requests

1 participant