Search code examples
watchkitios9watchos-2apple-watch-complication

Handle tap on complication under watchOS 2


I have a timeline with entries of different types and I need a way to navigate a user to a specific interface controller (or the same controller but with a different context) depending on an entry type has been tapped. Is there any way to handle a tap on a complication under watchOS 2?


Solution

  • In you main interface controller, override handleUserActivity:(NSDictionary *) userInfo like this:

    -(void)handleUserActivity:(NSDictionary *)userInfo
    {
        NSDate* timelineDate = userInfo[CLKLaunchedTimelineEntryDateKey];
        NSLog(@"%@", timelineDate);
    }
    

    You can know only the start date of the timeline entry, You can't figure out complication family(You mentioned it as entry type?) or other informations.

    At least, You can figure out whether the app is launched by complication.