watchOS 3 haptic feedback in background?

Working on Xcode 8 beta 3 and watchOS beta 3, using the background tasks new for watchOS 3. I'm experiencing the same problems as others on this forum where the task it getting spammed, but that is besides the point. Is it possible to play haptic feedback in a background task? Has anyone seen anything that determinantly says one way or the other? Thanks

Replies

Did you find a solution to this? Right now, with my research, it seems like you can only get background haptic feedback if you have a workout going.

My app is a fitness app and incoporates the .plist setting: WKBackgroundModes


But when I run haptic feedback in background on WatchOS3 simulator, I get the following printed in console:

WKInterfaceDevice playHaptic has no effect when executing in an inactive or background application state


I really hope this is either becuase we are sitll in beta or just on simulator. If not, this would be extremely disappointing.


[EDIT]: According to this, haptic feedback in background worked in WatchOS beta 2 and stopped working on beta 4. Might just be a bug. Important to point that this is for a workout app.

I have workout app as well and with BETA5 device work sometimes and simulator always seems to work. Not sure what's the correct behavior.

As of Beta 6 I got haptics in background working (and I also got confirmed that it is intenended to work).


My problem was that I didn't set the background keys as the documentation says:


"To run in the background, you must add the

WKBackgroundModes
key to your WatchKit extension’s
Info.plist
file. This key’s value is an array containing the
workout-processing
value. For more information, see WKBackgroundModes in Information Property List Key Reference.

To play audio or provide haptic feedback from the background, you must also add the

UIBackgroundModes
key to your WatchKit extension’s
Info.plist
file. This key’s value is an array containing the
audio
value."

Confirmed this is working. Can't belive there are no document on this.

To be fair: it's in the HealthKit docs but a bit buried. I didn't find it at first.

ethanfan could you please post code? I have added HealthKit and background mode plist properties but I am unable to play background haptic with XCode 8b6. Still getting:


WKInterfaceDevice playHaptic has no effect when executing in an inactive or background application state


for the line:

WKInterfaceDevice.current().play(.notification)


Is there a different call for this?


Thanks


Greg

I can confirm it works. There is nothing to change on the code side. I had the background flag in my info.plist except it was for some reason a string. Its actually an Array with one string key. Just make sure its exactly as follows and it should work.


You can open your .plist as source code and copy/paste it


  <key>WKBackgroundModes</key>
  <array>
  <string>workout-processing</string>
  </array>


EDIT: You of course have to have an active workoutSession

Figured it out. I did not have an active workoutSession.


Thanks


Greg

AHHhh you have to add BOTH the WKBackgroundModes and UIBackgroundModes keys. Note to self: MUST READ UNTIL THE END 😐

What did your code look like exactly? I want to make sure I'm doing it correctly.


Thanks!