Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WKRefreshBackgroundTask cleanupStorage Error attempting to reach file

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?

like image 336
Ryuuzaki Julio Avatar asked Sep 28 '17 08:09

Ryuuzaki Julio


1 Answers

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.

like image 140
MakeAppPie Avatar answered Oct 26 '22 03:10

MakeAppPie