Sample code on dynamic UIApplicationShortcutItems

前端 未结 4 901
眼角桃花
眼角桃花 2021-02-04 10:32

I\'m looking after some Obj-C sample code for a dynamic UIApplicationShortCutItem.

Basically, I have three static UIApplicationShortcutItems an

4条回答
  •  隐瞒了意图╮
    2021-02-04 10:58

    Here's how to detect if the app was launched with a quick shortcut in Objective-c.

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
    
    UIApplicationShortcutItem *shortcutItem = [launchOptions objectForKey:UIApplicationLaunchOptionsShortcutItemKey];
        if(shortcutItem){
            [self handleShortCutItem:shortcutItem];
        }
    }
    
    - (void)handleShortCutItem:(UIApplicationShortcutItem *)shortcutItem  {
        if([shortcutItem.type isEqualToString:@"takePhotoAction"]){
            //ACTION HERE
        }
    }
    

    To detect the type of shortcut selected while the app is running in the background.

    - (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler {
    NSLog(@"%@", shortcutItem.type);
        if([shortcutItem.type isEqualToString:@"takePhotoAction"]){
            //ACTION HERE
        }
    }
    

提交回复
热议问题