WatchKit app "Unlock to activate" - ios

My IOS app reads the heart rate from a bluetooth heart rate sensor, the heart rate is displayed on the Apple Watch. Everything works fine. But in most cases the user will lock the iPhone and put it in his pocket.
Here is the problem:
The IOS app is still working in the background and reading the heart rate but I can no longer display the data on the Apple Watch because the simulator displays "Unlock to activate".
Is it not possible to continue with the WatchKit app when the iPhone is locked and the IOS app is in the background?

I found the correct answer at the Apple Developer Forum:
Q: If you would like to debug willActivate/didDeactivate in a specific Interface Controller in your WatchKit app or Glance, once it is showing in the iOS Simulator, you can choose Hardware > Lock from the iOS Simulator menu bar to trigger didDeactivate. Repeat to unlock and trigger willActivate.
I found this in beta4, but some confusion. Is it just a test function in simulator? The app on real watch would not be locked after iphone locked, right?
A: Correct, it's just for testing.
Q: Is there a way to test the watch app in the simulator while the phone is locked? It seems like this would be an important test case as well, but right now the watch only shows "unlock to activate" while the phone is locked.
A: Not currently.
Link: (but you mast have a developer account) https://devforums.apple.com/message/1106203#1106203

Did you try something like this: Easy way to update app content via apple watch
Does calling openParentApplication not work when the iphone is locked?

When it comes to getting the iPhone to perform things in the background, openParentApplication works very well. Essentially, openParentApplication will run while your phone is locked.
This link: http://www.bignerdranch.com/blog/watchKit-extensions-communicating-with-your-parent-application/
has one of the best and easiest to understand tutorials I've found. Really helped me out, hope that helps.
You should be able to grab your data using openParentApplication
Good luck

Active background mode to ensure that the parent app has time to send its reply. For a code example on how to use the background mode, refer to Calling parent application from Watch app.

Related

Trigger apple watch application launch from iPhone [duplicate]

I would like to give a hint to the user, that my iOS app supports the Apple Watch.
So I would like to link/open the Apple Watch companion app from within my iOS app, very much similar to opening the Settings App using ([[UIApplication sharedApplication] openURL: [NSURL URLWithString:UIApplicationOpenSettingsURLString]];)
This shall enable the user to directly navigate to the Watch companion app to setup my app for the watch.
I could not find any URL which would open the companion app in general or specific to a section of the companion app.
If direct linking is not supported, I am also interested in alternative approaches for this use case.
Thanks in advance!
EDIT:
I checked the WatchKitSettings Info.plist file in the simulator to see if it registers any URL schema, but it does not.
I guess it's not possible to programmatically launch the watch companion app from iOS. The opposite way would be possible: to launch the iOS app in the background upon receiving a message from the watch. See WWDC talk Introducing Watch Connectivity.
You could check WCSession.defaultSession().watchAppInstalled and ask the user to launch the app if it is true.
Previously, it was not possible to launch the WatchKit App from the iPhone app, but the iPhone app could be launched—only in the background—with the openParentApplication method.
As of WatchOS 2, however, it is now not possible for either app to cause the other to launch. Instead, there are new methods for queueing changes to be picked up when the other app is launched in the future.
One partial solution for your use case could be displaying a local notification which could be tapped to open the watch app. The primary flaw in such an approach is I do not believe there is a way to limit this notification to the Watch only, so it would also appear on the iPhone where if tapped it would bring the iPhone app to the foreground. Messy if implemented like this, and therefore not worth it I'd have thought, even if it could pass app store review.

How to programmatically open Apple Watch companion app from iOS app

I would like to give a hint to the user, that my iOS app supports the Apple Watch.
So I would like to link/open the Apple Watch companion app from within my iOS app, very much similar to opening the Settings App using ([[UIApplication sharedApplication] openURL: [NSURL URLWithString:UIApplicationOpenSettingsURLString]];)
This shall enable the user to directly navigate to the Watch companion app to setup my app for the watch.
I could not find any URL which would open the companion app in general or specific to a section of the companion app.
If direct linking is not supported, I am also interested in alternative approaches for this use case.
Thanks in advance!
EDIT:
I checked the WatchKitSettings Info.plist file in the simulator to see if it registers any URL schema, but it does not.
I guess it's not possible to programmatically launch the watch companion app from iOS. The opposite way would be possible: to launch the iOS app in the background upon receiving a message from the watch. See WWDC talk Introducing Watch Connectivity.
You could check WCSession.defaultSession().watchAppInstalled and ask the user to launch the app if it is true.
Previously, it was not possible to launch the WatchKit App from the iPhone app, but the iPhone app could be launched—only in the background—with the openParentApplication method.
As of WatchOS 2, however, it is now not possible for either app to cause the other to launch. Instead, there are new methods for queueing changes to be picked up when the other app is launched in the future.
One partial solution for your use case could be displaying a local notification which could be tapped to open the watch app. The primary flaw in such an approach is I do not believe there is a way to limit this notification to the Watch only, so it would also appear on the iPhone where if tapped it would bring the iPhone app to the foreground. Messy if implemented like this, and therefore not worth it I'd have thought, even if it could pass app store review.

Text reply after watchOS notification is failing only when the corresponding app is installed on the watch

I have an iOS9 app with a watchKit 1.0 Extension. Most functionality is working fine. One of the main features of the app is a private messaging feature, which is also working great.
I'm using UIUserNotificationActionBehaviorTextInput for iOS9+ devices so that when a user receives a notification on their watch, they will be able to use the built in reply feature.
This works great, but only if the watchKit app is NOT installed on the watch. Users are able to reply to a notification on their watch with canned responses, or dictate a response with no problems. Note, this does NOT launch the watchKit app - it just uses the built-in reply functionality of the watch.
When the watchKit app IS installed on the watch, the "Message" and "Dismiss" buttons appear as expected. But as soon as someone clicks the Message button, instead of being able to tap or dictate a response, it just immediately goes back to the watch face.
It is 100% reproducible using two separate sets of an iPhone 6 running iOS9.1 and Apple Watch running watchOS 2.0.1. Since notifications can't be tested in the simulator, this is a very difficult problem to troubleshoot.
I could really use some guidance in what steps to take next.

Debug WatchKit on real Apple Watch - Nothing happens

I am struggling with debugging my WatchKit Extension/App on a real Apple Watch. Debugging both the iPhone App and the WatchKit Extension using the simulator the simulator is not problem:
Select the WatchKit App Profile and run in Simulator ==> App is launched on in Watch Simulator and I can use breakpoints in the Extension code to debug.
To debug the iPhone app as well I launch the app in the simulator and attach the debugger manually ==> I can use breakpoints in the iPhone Code to debug.
It is no problem to observe both the work of the iPhone app and the watch app. At least not in the simulator.
I would like to do the same thing on a real Apple Watch. But when I select the WatchKit App Profile and my real iPhone (instead of the Simulator) and click on "Run" nothing happens. This means Xcode seems to build and start the app but nothing happens on the devices. The status field in Xcode shows:
Building MyApp WatchKit App: MyApp WatchKit Extension
Building MyApp WatchKit App: Finishing...
Running MyApp on My iPhone 6
This is all. No debug Window, breakpoints are ignored or do not work and the app is not launched neither on the iPhone or on the Apple Watch.
I found other questions about problems with debugging on real devices (e.g. here) but they all deal with installation and signing issues. In my case both the iPhone App and the WatchKit App are installed without any problem. When I click the app icon on the Watch I can start and use the app. Problem is that I cannot debug this process.
Why do I need to debug the process on real devices? Well there is one thing I cannot test using the simulator: What happens when the Watch App tries to contact the iPhone app using openParentApplication:reply: when the iPhone app is not already running? This works perfectly in the simulator but on real devices the Watch Apps seems to get no reply from the iPhone app and simply waits forever.
I already found hints to solve this but without being able to debug the Watch App and to see how the code is executed I cannot be sure what is going on...
thank you for your answers. I finally managed to get the debugging running (most of the time) on my real Apple Watch. However it is quite cumbersome and not very reliable. There is not enough space in the comments so I will use this answer to describe my solution. Maybe it is help full to other:
Make sure, the App on your Watch is not running (as BalestraPatrick described). Launch the app and hold the side button a few seconds to bring up the "Turn off your Watch" dialog. Hold the side button for another few seconds to close the app and to return to the Watch homescreen.
Make sure the iPhone is not locked.
Select the WatchKit App target and your real iPhone and run the project.
Running the Watch App resulted quite often in an error SPErrorInvalidBundleNoGizmoBinaryMessage. Re-starting Xcode and cleaning both the Watch App and the App target solved this.
If the build of the Watch App succeed there will be a short message in Xcode but nothing on your iPhone or Watch. If you have made changes to the Watch App it will take a few seconds to refresh the app on the Watch. This is indicated by the progress-circle overlay over the app icon. If you made no changes ore once the app has been transfered: Launch the watch app manually by tapping the icon. There will be no automatic launch.
In most cases Xcode will recognize the app launch and attach its debugger to it. This will allow to use breakpoints, inspect the code, etc.
In my case I whanted to inspect how the iPhone App handles the application:handleWatchKitExtensionRequest:reply: call when the app was not active before. This is important because this cannot be done using the simulator. If the app takes to long to handle the request the Watch will receive no valid response.
After following the steps described above Xcode is only attached the watch app and will not hold on breakpoints in the iPhone app code. To do this, one has to manually attach the Debugger to the iPhone app process that is started when the watch app sends its call.
To be able to attach the debugger I added a delay to the apps main function: [NSThread sleepForTimeInterval:5]:
Select function in Watch App that will start the call to the iPhone App
The iPhone App will be launched in background. The delays gives you 5 seconds to attach the debugger.
Choose Debug\Attach To Process\Likely Targes\Your iPhone Appin Xcode to attach the debugger.
After the 5 seconds delay the process will continue and you will be able to use breakpoints in your iPhone app code as well.
Do not forget do remove the delay code when you finished testing :-)
NOTE:
You will not be able to see NSLog output (or any console output at all) from the iPhone App since attaching the debugger does NOT re-route the console output.
Happy testing with this awesome new Apple product :-P
I am having the same kind of issue but to improve a little bit the debugging experience I usually restart my devices a few times. Try to restart your Apple Watch or your iPhone.
Before launching your app from Xcode, make sure that the app is completely closed on your Apple Watch (not stuck in the loading screen for example). To do that, you have to force close the app: enter your app, keep the side button pressed until the menu to turn off the watch appears, then press the same side button for a few more seconds until the watch will go back to the homescreen and force close your app.
Now you can try to build and run the app from Xcode and it should work more reliably.
watchOS 3+:
The force quit is done by pressing and holding the side button (the button just below the Digital Crown) until the shutdown screen appears, and then
let go of the side button, then press and hold the Digital Crown.
Here's a technique that seems to be be the most reliable for me, even though it still only works about 25% of the time (Xcode 7 beta 4, 7A165t):
Run the phone target in debug (on your actual iPhone of course)
While the iPhone app is still running, switch to the watch target and run that in debug.
Keep an eye on your watch homescreen as the app installs. Once the app has installed, tap it to open it. This will sometimes "kickstart" the watch app and allow the debugger to catch it. At this point you should be able to debug both your iPhone app and watchOS app together.
This question has different answers. All are good.
The reason is: in my experience there are at least two different problems that prevent debugging on a real watch. Both require a different strategy.
This answer tries to help you to decide when to use which strategy.
XCode installs, tells you it is running for a short time and then stops showing "running...".
start with the answer of BalestraPatrick:
restart your devices.
Do not forget to restart your iPhone. This did the trick the first time I had this problem.
XCode installs, tells you it is running for a longer period of time: "running <projectName> on Apple Watch of <yourname>.
start with the answer of Jay Hickey or Andrei Herford
starting the watch app manually probably does the trick.
I also had times when XCode was able to start my watch app without any help from me.
Bonus:
Starting with XCode 7.1 it seems XCode doesn't always compile all necessary Swift files (more often than before). This is not watch specific, it also applies to iOS apps. The symptoms can look similar to those of this question. -> clean your project and then restart XCode.

iOS Watchkit: Is it possible to show static UI in Watch when app is not reachable?

Can we show some static UI in the watch when iPhone is not reachable to AppleWatch?
Suppose I forgot my iPhone at car seat , and when I move from car, Is it possible to shows some static UI in AppleWatch that you forgot your iPhone?
From an Apple evangelist on https://devforums.apple.com/thread/254576?tstart=0
The end result is that if iPhone is unreachable, the app will not
function. There is not a way to currently cache information to keep it
alive or seemingly so.
Actually you don't have to do anything. I noticed on the real Watch, that Apple will present a default "iPhone unavailable" screen in case the iPhone is out of reach. Similarly, Apple will also present a default "flight mode" screen when the Watch is in flight mode :) . See attached screenshots.
In WatchOS 2, it is now possible to have a WatchKit App that runs on the Watch when the iPhone is not accessible.
Previous answer:
It is clear from Apple's public statements and the WatchKit API that third party developers do not need to manage the connectivity between the watch and the phone, and indeed cannot even if they want to.
Given Apple have publicly indicated that Watch app interactions are expected to be measured in seconds, not minutes, and that developers need to assume that their Watch app could be quit at any time (and the associated WatchKit extension) it seems highly likely that there will not be any option to present static content in the event of the phone being unreachable—as the Watch OS will immediately take over the process of interacting with the user.
It seems almost certain that this will change later in 2015, given developers have been told there will be an SDK to develop 'fully native' apps at that time.
Technically speaking you could start off the app storyboard scene with static content. if the phone is unreachable, then this scene will be displayed. But as soon as your app, whether programmatically or by user interaction attempts to use anything from the WatchKit Extension, a spinner will appear.

Resources