8

在模拟器上的 WatchOS4 中创建 URLBGTask 时出现此错误是什么?

2017-09-28 16:05:26.452999+0900 MiFollowers WatchKit Extension[4628:4012814] [bg_app_refresh] -[WKRefreshBackgroundTask cleanupStorage]_block_invoke:213: Error attempting to reach file:///Users/ryuuzaki/Library/Developer/CoreSimulator/Devices/2E4D6389-93B7-4542-B07F-9A02C720B9AF/data/Containers/Data/PluginKitPlugin/FA4415DF-D984-4394-80B9-EDA199AB587E/Library/com.apple.watchkit/bktaskapp_(null): Error Domain=NSCocoaErrorDomain Code=260 "The file “bktaskapp_(null)” couldn’t be opened because there is no such file." UserInfo={NSURL=file:///Users/ryuuzaki/Library/Developer/CoreSimulator/Devices/2E4D6389-93B7-4542-B07F-9A02C720B9AF/data/Containers/Data/PluginKitPlugin/FA4415DF-D984-4394-80B9-EDA199AB587E/Library/com.apple.watchkit/bktaskapp_(null), NSFilePath=/Users/ryuuzaki/Library/Developer/CoreSimulator/Devices/2E4D6389-93B7-4542-B07F-9A02C720B9AF/data/Containers/Data/PluginKitPlugin/FA4415DF-D984-4394-80B9-EDA199AB587E/Library/com.apple.watchkit/bktaskapp_(null), NSUnderlyingError=0x79b0e340 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}

你们中的任何一个聪明的人都知道这一切意味着什么吗?

4

1 回答 1

5

我也得到了这个。最近两天让我发疯。

我仍然不确定要求您使用该userInfo属性是错误还是“功能”。如果您没有userInfo从方法中的后台刷新任务中获取属性,则会发生这种情况handle(_ backgroundTasks)。对该物业的任何访问都有效。摆脱错误的一个简单解决方法是在handle方法中安排下一次后台刷新,并backgroundTask.userInfo在参数中设置该userInfo:参数,该参数只分配nil给下一个任务。

WKExtension.shared().scheduleBackgroundRefresh(withPreferredDate: refreshDate, userInfo: backgroundTask.userInfo) { (error) in
    if let error = error {
        print ("Background task error:\(error.localizedDescription)")
    }
}

当然,这种解决方法意味着您将无法使用userInfo. 更好的代码可能是在其中粘贴一些东西,例如调度日期或任务的标识符,或者[String:Any]两者的字典。

于 2017-12-28T20:46:18.670 回答