自定義iWatch App點擊Glance後的跳轉頁

最新版的在iWatch2.0中的點擊Glance自定義的界面跳轉web

到今天爲止(2015年11月20日)的官方給出的方法是:app

當你的手錶app上顯示的快速信息瀏覽界面(Glance界面的時候),若是用戶點擊了這個界面,默認是跳轉到手錶app的主界面(也就是默認的InterfaceController界面的),但當你須要從新定義這個過程,但願能夠跳轉到你指定的界面的時候,按照下面的步驟:code

在Glance控制器中:orm

  • 定義glance,在init和willActivate方法
  • 在Glance被點擊的時候(在willActivate方法中),調用updateUserActivity:userInfo:webpageURL:方法,並經過userInfo參數指定傳輸的信息,在界面跳轉的時候,app就會跳轉到你指定的界面

例如:it

- (void)willActivate {
    // This method is called when the controller is about to be visible to the wearer.
    NSLog(@"%@ will activate", self);

    // Use Handoff to route the wearer to the image detail controller when the Glance is tapped.
    [self updateUserActivity:@"com.example.apple-samplecode.WatchKit-Catalog" userInfo:@{@"controllerName": @"imageDetailController", @"detailInfo": @"This is some more detailed information to pass."} webpageURL:nil];
}

在主控制器(InterfaceController)io

  • 實現handleUserActivity:方法,使用提供的userInfo字典定義UI。
    例如:
- (void)handleUserActivity:(NSDictionary *)userInfo {
    // Use data from the userInfo dictionary passed in to push to the appropriate controller with detailed info.
    [self pushControllerWithName:userInfo[@"controllerName"] context:userInfo[@"detailInfo"]];
}

好了,你再次運行試試看吧。form

相關文章
相關標籤/搜索