Ionic4--Camera插件在iOS13上選取視頻失敗

iOS13獲取本地視頻的路徑:

file:///private/var/mobile/Containers/Data/PluginKitPlugin/43792FA5-A8F8-4ECA-8CCE-0C5877088858/tmp/trim.7F9B8FC4-3307-4452-9F96-46A5D9A9DDD5.MOV

比iOS12多了一個 PluginKitPlugin 的文件夾,導致文件訪問受限。

解決方法:

找到 CDVCamera.m 文件

in CDVCamera.m change THIS:

    (CDVPluginResult*)resultForVideo:(NSDictionary*)info
    {
    NSString* moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] absoluteString];
    return [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:filePath];
    }

to THIS:

    (CDVPluginResult*)resultForVideo:(NSDictionary*)info
    {
    NSString* moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];

    NSArray* spliteArray = [moviePath componentsSeparatedByString: @"/"];
    NSString* lastString = [spliteArray lastObject];
    NSError *error;
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"tmp"];
    NSString *filePath = [documentsDirectory stringByAppendingPathComponent:lastString];
    [fileManager copyItemAtPath:moviePath toPath:filePath error:&error];

    return [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:filePath];
    }

Mark一下,附上問題答案地址:https://github.com/apache/cordova-plugin-camera/issues/506

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章