はここでアプリが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
}
}
アプリがバックグラウンドで実行されている間に選択されたショートカットのタイプを検出します。
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler {
NSLog(@"%@", shortcutItem.type);
if([shortcutItem.type isEqualToString:@"takePhotoAction"]){
//ACTION HERE
}
}
Objective-Cのショートカットからアプリを起動した場合、どのように検知しますか? – user1752054
あなたは 'application:didFinishLaunchingWithOptions'または' application:willFinishLaunchingWithOptions'をチェックすることができます。アプリがショートカットから起動されるかどうか。ショートカットから起動された場合、launchOptions辞書には 'UIApplicationLaunchOptionsShortcutItemKey'が含まれていなければなりません。そして、shortCutDemoリポジトリhttps ://github.com/cp0000/shortcutDemoを参照してください。 – chengpei