Upgrade to Pro — share decks privately, control downloads, hide ads and more …

debug-remote-local-notification-on-watchos

 debug-remote-local-notification-on-watchos

potatotips #28

3652e140db258288623a0adf248baec0?s=128

Shinichi Goto

April 20, 2016
Tweet

Transcript

  1. Debug Remote / Local No1fica1on on watchOS ɹ potato%ps-28 2016/4/20

    @shingt
  2. Wantedly

  3. No#fica#ons

  4. None
  5. watchOS No+fica+on Components • Short-look • Long-look • Sta.c •

    Dynamic • Remote or Local • Ac.onable items • First view (kinds different from iOS)
  6. watchOS No+fica+on Components • Short-look • Long-look • Sta.c •

    Dynamic • Remote or Local • Ac.onable items • First view (kinds different from iOS)
  7. Complicated (Compared to iOS)

  8. Debugging

  9. Debug No)fica)on • Remote no)fica)on • On simulator • On

    device • Local no)fica)on • On simulator • On device
  10. Remote No(fica(on • On simulator • Provided on Xcode !

    • Custom Build Scheme with No8fica8on Interface • Describe no8fica8on payload in json • breakpoint "
  11. MessagePayload.apns { "aps": { "alert": { "body": "Wantedly, Inc.͔Βϝοηʔδ͕ಧ͖·ͨ͠", "title":

    "৽ணϝοηʔδ" }, "category": "MESSAGE_CATEGORY", }, "message": { "id": 1, "body": "͜Μʹͪ͸ʂాதͰ͢ɻ\n͜ͷ౓͸WantedlyʹڵຯΛ࣋ͬͯ௖͍ͯ͋Γ͕ͱ͏͍͟͝·͢ɻ", "company_name": "Wantedly, Inc.", ... }, "WatchKit Simulator Actions": [ ... ] }
  12. Remote No(fica(on • On simulator • Provided on Xcode !

    • Custom Build Scheme with No:fica:on Interface • Describe no:fica:on payload in json • breakpoint " • On device • Just send it :)
  13. Local No(fica(on on Simulator • Want • Easily debug •

    Problem • Not provided on Xcode • Different from remote no=fica=on on simulator • Solu=on? • Use remote no=fica=on debugging instead?
  14. Solu%on? ## Debug override func didReceiveRemoteNotification( remoteNotification: [NSObject : AnyObject],

    withCompletion completionHandler: (WKUserNotificationInterfaceType) -> Void) {...} ## Production override func didReceiveLocalNotification( localNotification: UILocalNotification, withCompletion completionHandler: (WKUserNotificationInterfaceType) -> Void) {...}
  15. Problem ## Debug override func didReceiveRemoteNotification( remoteNotification: [NSObject : AnyObject],

    withCompletion completionHandler: (WKUserNotificationInterfaceType) -> Void) {...} ## Production override func didReceiveLocalNotification( localNotification: UILocalNotification, withCompletion completionHandler: (WKUserNotificationInterfaceType) -> Void) {...} ɹ remoteNotification != localNotification
  16. Sender UILocalNotification *notification = [UILocalNotification new]; notification.alertBody = [company.name stringByAppendingString:@"͕ۙ͘ʹ͋Γ·͢"];

    notification.alertTitle = @"ۙ͘ͷձࣾ"; notification.category = @"COMPANY_LOCATION"; notification.userInfo = [company toJSON];
  17. Prepare wrapper object

  18. None
  19. None
  20. • Easy to debug • Assump1on: NotificationPayload works appropriately •

    Cannot test sender
  21. Local No(fica(on on Device • Problem • Hard to send

    (depending on applica5on) • Needs to send no5fica5on while iOS device is asleep • Solu5on • Basically same as debugging iOS local no5fica5on
  22. - (void)application:(UIApplication *)application performFetchWithCompletionHandler:... { ... [self methodForLocalNotification]; // For

    debug ... }
  23. Run iOS app => Sleep => "Simulate Background Fetch"

  24. Summary • Debugging No,fica,on • Remote...؆୯ • Local...γϛϡϨʔλͷ৔߹͸ͪΐͬͱ޻෉͢Δ ͱྑͦ͞͏

  25. ऴΘΓ !