基本步骤如下
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[self setup3DTouch];
return YES;
}
- (void)setup3DTouch
{
UIApplicationShortcutIcon *icon1 = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeHome];
UIMutableApplicationShortcutItem *item1 = [[UIMutableApplicationShortcutItem alloc]initWithType:@"com.3dtouch.hello" localizedTitle:@"Helo, 3DTouch" localizedSubtitle:nil icon:icon1 userInfo:nil];
NSArray *items = @[item1];
[UIApplication sharedApplication].shortcutItems = items;
}
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void(^)(BOOL succeeded))completionHandler
{
NSLog(@"%@", shortcutItem.type);
if([shortcutItem.type isEqualToString:@"com.3dtouch.hello"])
{
// 处理回调
}
}
但是xcode11新建的项目则没有调用- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void(^)(BOOL succeeded))completionHandler
xcode11新建项目会多一个SceneDelegate类
iOS13 Scene Delegate详解
App在后台通过3dtouch进入App会调用- (void)windowScene:(UIWindowScene *)windowScene performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler