Watchkit Extension Cannot Read from Icloud

Watchkit Extension Cannot Read from iCloud

I have officially heard back from Apple that this is not a supported feature of Watch OS. This runs contrary to their own documentation which I let them know about. Hopefully others see this response and it can save a ton of time that I wound up wasting.

NSUbiquitousKeyValueStore Unavailable on Watch OS 3.1.3

I have officially heard back from Apple that this is not a supported feature of Watch OS. This runs contrary to their own documentation which I let them know about. Hopefully others see this response and it can save a ton of time that I wound up wasting.

Can't read iCloud file from second device that was written on first device

Well, I didn't give up and I now think I have an acceptable work around for this problem.
The key to the solution is for the second device to be able to successfully detect the token file that was written to the ubiquity container by the first device, and not try to write the file itself.

Here are the steps that work for me:

  • Immediately try to read the token file from the container.
  • If successful, use the file and ignore the rest of the steps.
  • Otherwise, start a meta data query whose predicate will trigger on two specific file names (the token file you are trying to read and a "dummy" file).
  • Now write a file to the ubiquity container with the dummy file name.
  • As the results for the meta data query arrive, check the upload/download status for the files that it reports.
  • If the query ever reports seeing the token file, then this is NOT the first device and it should continue to try to read the file until successful. It may take a while, but it will eventually read it.
  • If the meta data query reports the dummy file as being completely uploaded and there is still no sign of the token file, then it's safe to assume this is the first device and it's now OK to write the token file.
  • I find it useful to wait until the status of the token file is completely uploaded before trying to use the token. Otherwise, if there are network issues, another device also starting this process may do the same thing and also think it's the first device.

It seems that the writing of the dummy file to the ubiquity container "kick starts" the meta data query enough to get it to report the existence of the token file on a second device. Without it, the meta data query never reports the existence of the token file on anything other than the first device.

Access contents of Watchkit extension's host's mainBundle

The host app and your WatchKit extension can share files in only one of two ways, as far as I know:

  • Shared app group
  • Including a file in both targets

They run in separate processes and aren't accessible to each other outside of approved methods.

How do I format webpageURL to get WatchKit to handoff user to a website in Safari?

Thanks to Schemetrical who pointed out my error in thinking that

  QueryVar.description

would yield only the elements of an array stringified. As that variable contained brackets and commas it was illegal content for an NSURL type. I cleaned up the code and got to a working solution:

 var URLwithQuery = "http://www.example.com?query="+QueryVar

var urlPath: String = URLwithQuery
var website: NSURL = NSURL(string: urlPath)!

updateUserActivity("com.example.myapp.anactivity", userInfo: nil, webpageURL: website)


Related Topics



Leave a reply



Submit