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

Shinichi Goto

April 20, 2016
Tweet

More Decks by Shinichi Goto

Other Decks in Programming

Transcript

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

    View Slide

  2. Wantedly

    View Slide

  3. No#fica#ons

    View Slide

  4. View Slide

  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)

    View Slide

  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)

    View Slide

  7. Complicated
    (Compared to iOS)

    View Slide

  8. Debugging

    View Slide

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

    View Slide

  10. Remote No(fica(on
    • On simulator
    • Provided on Xcode !
    • Custom Build Scheme with No8fica8on Interface
    • Describe no8fica8on payload in json
    • breakpoint "

    View Slide

  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": [
    ...
    ]
    }

    View Slide

  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 :)

    View Slide

  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?

    View Slide

  14. Solu%on?
    ## Debug
    override func didReceiveRemoteNotification(
    remoteNotification: [NSObject : AnyObject],
    withCompletion completionHandler: (WKUserNotificationInterfaceType)
    -> Void) {...}
    ## Production
    override func didReceiveLocalNotification(
    localNotification: UILocalNotification,
    withCompletion completionHandler: (WKUserNotificationInterfaceType)
    -> Void) {...}

    View Slide

  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

    View Slide

  16. Sender
    UILocalNotification *notification = [UILocalNotification new];
    notification.alertBody = [company.name
    stringByAppendingString:@"͕ۙ͘ʹ͋Γ·͢"];
    notification.alertTitle = @"ۙ͘ͷձࣾ";
    notification.category = @"COMPANY_LOCATION";
    notification.userInfo = [company toJSON];

    View Slide

  17. Prepare wrapper object

    View Slide

  18. View Slide

  19. View Slide

  20. • Easy to debug
    • Assump1on: NotificationPayload works
    appropriately
    • Cannot test sender

    View Slide

  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

    View Slide

  22. - (void)application:(UIApplication *)application
    performFetchWithCompletionHandler:...
    {
    ...
    [self methodForLocalNotification]; // For debug
    ...
    }

    View Slide

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

    View Slide

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

    View Slide

  25. ऴΘΓ !

    View Slide