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

{com.facebook.sdk:FBSDKErrorArgumentNameKey=videoURL, com.facebook.sdk:FBSDKErrorDeveloperMessageKey=Must refer to an asset file., com.facebook.sdk:FBSDKErrorArgumentValueKey=/var/mobile/Media/DCIM/100APPLE/IMG_0201.MOV} #2466

Open
5 tasks done
fengpuchao opened this issue Aug 14, 2024 · 0 comments

Comments

@fengpuchao
Copy link

Checklist before submitting a bug report

Xcode version

15.3

Facebook iOS SDK version

v17.0.3

Dependency Manager

Prebuilt Binaries

SDK Framework

Share

Goals

我想通过这三个任意的属性将视频分享到Facebook里面
/// The raw video data.
@Property (nonatomic, copy) NSData * _Nullable data;
/// The representation of the video in the Photos library.
@Property (nonatomic, strong) PHAsset * _Nullable videoAsset;
/// The file URL to the video.
@Property (nonatomic, copy) NSURL * _Nullable videoURL;

Expected results

将选中的视频分享到Facebook

Actual results

Error Domain=com.facebook.sdk.share Code=2 "(null)" UserInfo={com.facebook.sdk:FBSDKErrorArgumentNameKey=videoURL, com.facebook.sdk:FBSDKErrorDeveloperMessageKey=Must refer to an asset file., com.facebook.sdk:FBSDKErrorArgumentValueKey=/var/mobile/Media/DCIM/100APPLE/IMG_0201.MOV}

Steps to reproduce

用这三方都无法实现视频的分享
/// The raw video data.
@Property (nonatomic, copy) NSData * _Nullable data;
/// The representation of the video in the Photos library.
@Property (nonatomic, strong) PHAsset * _Nullable videoAsset;
/// The file URL to the video.
@Property (nonatomic, copy) NSURL * _Nullable videoURL;

Code samples & details

我是这样实现的   
 PHFetchOptions *fetchOptions = [[PHFetchOptions alloc] init];
    fetchOptions.predicate = [NSPredicate predicateWithFormat:@"mediaType == %d", PHAssetMediaTypeVideo];
    fetchOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]];
    PHFetchResult<PHAsset *> *assets = [PHAsset fetchAssetsWithOptions:fetchOptions];
    PHAsset *asset = [assets firstObject];
    if (asset) {
        PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
        options.networkAccessAllowed = false;
        [[PHImageManager defaultManager] requestAVAssetForVideo:asset options:options resultHandler:^(AVAsset * _Nullable avAsset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) {
            if ([avAsset isKindOfClass:[AVURLAsset class]]) {
                AVURLAsset *urlAsset = (AVURLAsset *)avAsset;
                NSURL *videoURL = urlAsset.URL;
                id<FBSDKSharingContent> shareContent;
                FBSDKShareVideo *video = [FBSDKShareVideo alloc];
                video.videoURL = videoURL;
                FBSDKShareVideoContent *videoContent = [[FBSDKShareVideoContent alloc] init];
                videoContent.video = video;
                shareContent = videoContent;
                dispatch_async(dispatch_get_main_queue(), ^{
                    [FBSDKShareDialog showFromViewController:[UIApplication sharedApplication].delegate.window.rootViewController withContent:shareContent delegate:self];
                });
            }
        }];
    }
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

2 participants
@fengpuchao and others