Whats this error I get when making a URLBGTask in WatchOS4 on the Simulator?
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"}}
Any of you bright minds out there know what all this means?
I was getting this too. Drove me nuts for the last two days.
I'm still not sure if it is a bug or "feature" to require you to use the userInfo
property. This is happening if you don't get the userInfo
property from the background refresh task in the handle(_ backgroundTasks)
method. Any access of the property works. A simple workaround one to get rid of the error is to schedule your next background refresh in the handle
method with backgroundTask.userInfo
in the userInfo:
parameter which just keeps assigning nil
to the next task.
WKExtension.shared().scheduleBackgroundRefresh(withPreferredDate: refreshDate, userInfo: backgroundTask.userInfo) { (error) in
if let error = error {
print ("Background task error:\(error.localizedDescription)")
}
}
Of course this workaround means you won't be able to use userInfo
. Better code might be to stick something in there such as the scheduling date or an identifier for the task, or a dictionary of [String:Any]
for both.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With