18

I am trying to simulate the local notification view in apple watch simulator. Does any one known how to simulate the local notifications in apple watch ?

I have done some research for that but didn't found any answer for the above. There is a way to simulate the PUSH NOTIFICATION but not for the LOCAL NOTIFICATION.

NSAnant
  • 816
  • 8
  • 18
  • https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/WatchKitProgrammingGuide/ConfiguringYourXcodeProject.html ? – Larme Nov 28 '14 at 12:57
  • There s no answer yet, but totally a valid question. How can this be closed as too broad ??? – GoodSp33d Nov 28 '14 at 17:06
  • @Larme The link you have posted is for the PUSH NOTIFICATIONS not for the LOCAL NOTIFICATION – NSAnant Nov 29 '14 at 06:06

2 Answers2

25

It is not possible to have a Watch app react to a UILocalNotification in the simulator. However, it is almost identical to reacting to a push notification, except it gets routed through a couple of different methods.

If you're presenting an actionable notification, your WKUserNotificationInterfaceController subclass would override -didReceiveLocalNotification:withCompletion: instead of -didReceiveRemoteNotification:withCompletion:.

If your Watch app is getting launched in response to interacting with one of your actionable notifications, then your root WKInterfaceController would implement -handleActionWithIdentifier:forLocalNotification: or -handleActionWithIdentifier:forRemoteNotification:, as appropriate.

From WatchKit's point-of-view, those are the only distinctions between remote and local notifications.

Dave DeLong
  • 242,470
  • 58
  • 448
  • 498
  • 1
    Thanks, Is there any another way to design and test the local notification view in watch app ? – NSAnant Dec 05 '14 at 06:13
  • 3
    @NSAnant by putting the payload of your local notification into the PushNotificationPayload.json file and pretending that it's a remote notification. The point of my answer was to show that local and remote notifications get treated almost identically by the OS, and so you can treat them as almost entirely interchangeable. – Dave DeLong Dec 05 '14 at 15:00
  • @DaveDeLong did u get local notification in watch simulator if so then reply with proper code for triggering local notification in watch. Please dont say about notification recieve delegate methods everybody knows abt recieving tell abt triggering notification in watch – iOSdev Apr 21 '15 at 10:04
  • well thats a pain in the arse – anders Apr 24 '15 at 18:43
  • 2
    This is not strictly true since a local notification comes into the handlers as UILocalNotification while the remote notification comes in as [NSObject : AnyObject] – SeanR Nov 04 '15 at 01:14
8
  1. Run your watch app (notification target) on simulator, dismiss the notification and stay on clock face.

  2. Switch to iOS simulator and create a notification. For testing purposes setup fireDate to something reasonable like:

    notification.fireDate = NSDate().dateByAddingTimeInterval(10)

  3. Here goes the trick. Hit ⌘L to lock iOS simulator.

  4. Enjoy notification arriving to watch app.

Viktor Kucera
  • 6,177
  • 4
  • 32
  • 43