3D Touch Home Shortcuts In Obj-C

前端 未结 5 807
一整个雨季
一整个雨季 2021-01-30 05:37

All of my apps are currently written in Obj-C. The link https://developer.apple.com/library/content/samplecode/ApplicationShortcuts/Introduction/Intro.html#//apple_ref/doc/uid/

5条回答
  •  离开以前
    2021-01-30 06:20

    If you look at the sample code provided for apple, you'll see that they suggest that you write a method that handles your shortcut item so that you can handle it in all three places:

    • application: performActionForShortcutItem,
    • application: didFinishLaunchingWithOptions and
    • willFinishLaunchingWithOptions

    An example of what I did was:

    - (BOOL)handleShortCutItem:(UIApplicationShortcutItem *)shortcutItem {
        BOOL handled = NO;
    
        if (shortcutItem == nil) {
            return handled;
        }
    
        if ([shortcutItem.type isEqualToString:kFavoritesQuickAction]) {
            handled = YES;
        } 
    
        if (handled) {
            // do action here
        }
    
        return handled;
    }
    

    Then you would just call this method in any place where you are getting a shortcut item. This should help you along your way!

提交回复
热议问题