我创建了一个iOS快速查看预览扩展,每当用户执行Spotlight搜索并预览我的应用程序的结果时,iOS就会调用该扩展。预览加载正常,但是当我尝试从扩展名内访问云文件时,它失败并显示DNS错误,提示为Operation not permitted
。
我发现在MacOS上,我需要禁用沙箱功能,或者,如果使用沙箱功能,则需要授予网络访问权限,但这是iOS。这里没有这样的设置。我该如何运作?
这是我的扩展代码
#import "PreviewViewController.h"
#import <QuickLook/QuickLook.h>
@interface PreviewViewController () <QLPreviewingController>
@end
@implementation PreviewViewController
- (void)preparePreviewOfSearchableItemWithIdentifier:(NSString *)identifier queryString:(NSString * _Nullable)queryString completionHandler:(void (^)(NSError * _Nullable))handler {
NSURL *url = [NSURL URLWithString:@"https://myclouddomain.com"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
request.HTTPMethod = @"GET";
// [request setValue:headerFields[key] forHTTPHeaderField:key];
// request.HTTPBody = (NSData *)bodyData;
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration ephemeralSessionConfiguration];
NSURLSession *urlSession = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];
NSURLSessionDataTask *task = [urlSession dataTaskWithRequest:request completionHandler:^(NSData* data, NSURLResponse* response, NSError* error) {
if (error == nil) {
NSInteger responseCode = [(NSHTTPURLResponse*)response statusCode];
NSLog(@"OK (%d)", (int)responseCode);
} else {
NSLog(@"Failed");
}
handler (nil);
}];
[task resume];
}
这是日志输出
2019-04-03 10:42:20.809768 + 0200 QuickLookPreview [7655:3650321] dnssd_clientstub ConnectToServer:connect()->尝试次数:1
2019-04-03 10:42:21.815704 + 0200 QuickLookPreview [7655:3650321] dnssd_clientstub ConnectToServer:connect()->尝试次数:2
2019-04-03 10:42:22.821499 + 0200 QuickLookPreview [7655:3650321] dnssd_clientstub ConnectToServer:connect()->尝试次数:3
2019-04-03 10:42:23.827993 + 0200 QuickLookPreview [7655:3650321] dnssd_clientstub ConnectToServer:connect()失败的路径:/ var / run / mDNSResponder套接字:4 Err:-1 Errno:1不允许操作< / p>
2019-04-03 10:42:23.828797 + 0200 QuickLookPreview [7655:3650321] [] nw_resolver_create_dns_service_locked [C1] DNSServiceCreateDelegateConnection失败:ServiceNotRunning(-65563)
2019-04-03 10:42:23.831035 + 0200 QuickLookPreview [7655:3650321] TIC TCP连接失败[1:0x283aea040]:10:-72000 Err(-65563)
2019-04-03 10:42:23.833948 + 0200 QuickLookPreview [7655:3650323]任务。<1> HTTP加载失败(错误代码:-1003 [10:-72000])
2019-04-03 10:42:23.834811 + 0200 QuickLookPreview [7655:3650323]任务。<1>已完成但有错误-代码:-1003
失败