PFQuery findObjectsInBackgroundWithBlock: WatchKit app runs in simulator, not watch, unless iOS app is in foreground

I am writing a WatchKit application that needs to make a request to our Parse server. Since this is a network call, I follow this procedure:

  • I am making a call from WatchKit to an iOS app using openParentApplication:reply:

  • Internally, handleWatchKitExtensionRequest:userInfo:reply:

    I run a background job with UIBackgroundTaskIdentifier

    to ensure the iOS app terminates immediately.
  • I installed PFQuery

    mine and callfindObjectsInBackgroundWithBlock:

  • In the block I go to PFQuery, I will reply the relevant information to the watch

I wrote this app maybe a month ago before the Apple Watch came out and it did a great job with the Watch simulator. I got my Apple Watch yesterday and I managed to get the app to work on the watch, but it didn't quite work - I was able to figure out that when the iOS app is actively running in the foreground on the iPhone, then everything is Great; but if the app is inactive (for example, in the background or exited), then it findObjectsInBackgroundWithBlock:

never calls the block, and execution seems to just stop.

Does anyone have any idea what might be going on? My initial thought was that the iOS app pauses / kills before it can complete the request, but I was confident that the background task would prevent this.

PS. If anyone stumbles upon this question because they were looking for how to get the WatchKit app on a real watch, I found this post extremely helpful in getting it working.


source to share

1 answer

It turned out that I had several problems with openParentApplication: reply: and they all seemed to have been fixed using the technique from this post:

I started a background job for my own application, but I didn't use the "dummy workaround" focus task described in this post because it wasn't necessary for me in the simulator. However, it appears to have been on the clock.



All Articles