我需要在臉書上分享視頻,並擁有此視頻的fileURL,但要分享,我需要此視頻的資源網址。如何在不使用UIImagePickerViewController的情況下從本地視頻獲取資產URL?在Facebook上分享視頻與iOS SDK
0
A
回答
0
import FacebookShare
let shareDialog = ShareDialog(content: myContent)
shareDialog.mode = .Native
shareDialog.failsOnInvalidData = true
shareDialog.completion = { result in
// Handle share results
}
try shareDialog.show()
請參閱Facebook的開發API獲取更多詳細信息
https://developers.facebook.com/docs/swift/sharing/share-dialog
0
的Facebook SDK要求資源網址,所以你有你的視頻文件傳遞到資產庫,並從中獲得新的URL。完整的代碼如下所示:
NSURL *_videoURL = [URL to local video file];
//initilize the asset library object and define the completion block
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
ALAssetsLibraryWriteVideoCompletionBlock videoWriteCompletionBlock =
^(NSURL *newURL, NSError *error) {
if (error) {
NSLog(@"Error writing image with metadata to Photo Library: %@", error);
} else {
NSLog(@"Wrote image with metadata to Photo Library %@", newURL.absoluteString);
//share to facebook when we have new asset URL
FBSDKShareVideo *shareVideo = [[FBSDKShareVideo alloc]init];
shareVideo.videoURL = newURL;
FBSDKShareVideoContent *shareContent = [[FBSDKShareVideoContent alloc] init];
shareContent.video = shareVideo;
[FBSDKShareDialog showFromViewController:self withContent:shareContent delegate:nil];
}
};
//write video file and fire up facebook sharing diaglog when complete
if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:_videoURL])
{
[library writeVideoAtPathToSavedPhotosAlbum:_videoURL
completionBlock:videoWriteCompletionBlock];
}
修訂版(適用於iOS SDK 9.0或更高版本):
NSURL *_videoURL = [URL to local video file];
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetChangeRequest *changeRequest= [PHAssetChangeRequest creationRequestForAssetFromVideoAtFileURL:_videoURL];
_videoPlaceHolder= [changeRequest placeholderForCreatedAsset];
} completionHandler:^(BOOL success, NSError * _Nullable error) {
if (error) {
NSLog(@"Error writing image with metadata to Photo Library: %@", error);
} else {
NSLog(@"Wrote image with metadata to Photo Library %@", [_videoPlaceHolder localIdentifier]);
//example for localidentifier:2BC8A8A8-E974-42D9-AD0F-2F463B353914/L0/001
NSArray *id=[_videoPlaceHolder.localIdentifier componentsSeparatedByString:@"/"];
NSString *path= [NSString stringWithFormat:@"assets-library://asset/asset.MOV?id=%@&ext=MOV",id[0]];
_videoAssetURL = [NSURL URLWithString:path];
dispatch_async(dispatch_get_main_queue(), ^{
//share to facebook
FBSDKShareVideo *shareVideo = [[FBSDKShareVideo alloc]init];
shareVideo.videoURL = _videoAssetURL;
FBSDKShareVideoContent *shareContent = [[FBSDKShareVideoContent alloc] init];
shareContent.video = shareVideo;
[FBSDKShareDialog showFromViewController:self withContent:shareContent delegate:nil];
});
}
}];
+0
謝謝你的解決方案!但是'ALAssetsLibrary'已經被棄用了,我需要這個代碼在沒有'ALAssetsLibrary'的情況下工作,你知道嗎?! –
+0
請檢查我的更新以使用'PHPhotoLibrary'替換iOS SDK 9.0中的'ALAssetsLibrary',只需確保視頻文件的擴展名正確(默認爲MOV) –
相關問題
- 1. 在Facebook上共享視頻iOS SDK 4.4
- 2. 在Facebook上分享視頻鏈接ios
- 3. iOS Facebook分享視頻Swift
- 4. 在facebook上分享視頻
- 5. 在Facebook上分享視頻
- 6. 如何在Facebook SDK中分享視頻?
- 7. 通過適用於iOS的FB SDK將視頻分享至Facebook
- 8. 使用Facebook iOS SDK與標題共享視頻
- 9. 分享視頻鏈接到Facebook ios
- 10. 分享到Facebook的視頻
- 11. 在iOS上分享視頻到Instagram
- 12. 在開放圖譜上在Facebook上分享嵌入Facebook視頻
- 13. 在Pinterest上分享視頻
- 14. 分享視頻到Facebook牆
- 15. Facebook上分享SDK v3.13
- 16. 使用Android共享在Facebook上分享視頻Intent
- 17. ios上的ios Facebook SDK共享錯誤
- 18. 如何在Facebook上上傳/分享視頻?
- 19. 通過Facebook分享視頻sdk 4.x在Android應用程序
- 20. 在facebook壁上發佈youtube視頻與facebook的SDK在android中
- 21. 與Facebook分享,iOS上的twitter
- 22. Android意圖共享在Facebook上分享視頻網址
- 23. android facebook facebook - 分享位置,同時上傳視頻文件
- 24. 在Facebook上分享圖像 - iOS - Android
- 25. 以編程方式在iOS 6應用上分享Facebook上的視頻?
- 26. 與facebook共享內容sdk 4.0 + iOS
- 27. 在Facebook上分享照片Android SDK
- 28. 不能分享Facebook的視頻鏈接從PHP sdk
- 29. 在Facebook上分享
- 30. 如何使用JavaScript SDK分享視頻?
你只是爲例說明如何打開的對話框中,我知道如何打開它。我的問題是如何在不使用「UIImagePickerViewController」的情況下從本地視頻獲取資產URL。 –