没有读取iCloud Drive文件的权限 [英] No permission to read iCloud Drive file

查看:807
本文介绍了没有读取iCloud Drive文件的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户在Apple文件"应用程序中点击文件并选择我的应用程序以查看它时,我正在尝试让我的应用程序打开iCloud Drive文件.一切设置都很好,例如该应用已打开,并在用户点击该文件时收到通知.但是无法打开文件,并显示该应用没有权限打开该错误.

I am trying to make it possible for my app to open iCloud Drive files, when the user taps on the file in the Apple "Files" app, and selects my app to view it in. Everything is set up fine, such that the app gets opened, and notified when the user taps on the file. But it is not possible to open the file, with the error that the app has no permissions to do so.

我的应用程序在 Info.plist 中将支持就地打开文档"设置为是".这意味着URL指向应用程序外部的iCloud目录,这可能是问题的原因.如果将其设置为NO,则URL是应用程序内部文件的副本,并且一切正常.但是应用程序需要将该设置设置为是".

My app has "Supports opening documents in place" in the Info.plist set to YES. This means the URL points to an iCloud directory outside the app, which is probably the cause of the problem. If I set that to NO, then URL is a copy of the file inside the app, and everything works fine. But the app needs that setting to be YES.

我已经验证,并且该文件实际上实际存在于手机中.

I have verified, and the file is actually physically present on the phone.

有人知道如何做这项工作吗?

Anybody knows how to make this work?

我的 openURL:方法当前如下所示:

My openURL: method currently looks like:

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
    NSLog(@"path=%@", url);
    NSError *error = nil;
    NSData *data = [[NSData alloc] initWithContentsOfURL:url options:0 error:&error];
    NSLog(@"error=%@", error);
}

给出的错误是:

Error Domain = NSCocoaErrorDomain代码= 257文件"Kili.gpx"无法打开,因为您没有查看权限."UserInfo = {NSFilePath =/private/var/mobile/Library/Mobile文档/com~apple~CloudDocs/Kili.gpx,NSUnderlyingError = 0x283ac83f0{Error Domain = NSPOSIXErrorDomain代码= 1不允许操作"}}

Error Domain=NSCocoaErrorDomain Code=257 "The file "Kili.gpx" couldn’t be opened because you don’t have permission to view it." UserInfo={NSFilePath=/private/var/mobile/Library/Mobile Documents/com~apple~CloudDocs/Kili.gpx, NSUnderlyingError=0x283ac83f0 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}

推荐答案

我找到了解决方案.您需要使用 startAccessingSecurityScopedResource stopAccessingSecurityScopedResource

I found the solution. You need to surround the reading of the url with startAccessingSecurityScopedResource and stopAccessingSecurityScopedResource:

[url startAccessingSecurityScopedResource];
NSError *error = nil;
NSData *data = [[NSData alloc] initWithContentsOfURL:url options:0 error:&error];
[url stopAccessingSecurityScopedResource];

这篇关于没有读取iCloud Drive文件的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆