
截屏2021-04-30 下午3.48.21.png
首先支持3d Touch,設(shè)備iPhone 6s+,iOS9+之后新增的功能。兩種方式能實(shí)現(xiàn)--
(1)Info.plist 創(chuàng)建快捷方式

截屏2021-04-30 下午3.49.27.png
快捷方式支持在 Info.plist 里直接定義,主鍵是UIApplicationShortcutItems,它是一個(gè)數(shù)組Array。各個(gè) Key 值可以在查看Information Property List Key Reference,在這里簡(jiǎn)單地介紹一下各個(gè) Key 的作用。
Key 作用
UIApplicationShortcutItemType(必需) 唯一標(biāo)識(shí)
UIApplicationShortcutItemTitle(必需) 顯示的標(biāo)題
UIApplicationShortcutItemSubtitle(可選) 顯示的副標(biāo)題
UIApplicationShortcutItemIconType(可選) 使用系統(tǒng)的圖標(biāo)
UIApplicationShortcutItemIconFile(可選) 使用項(xiàng)目的圖標(biāo)
UIApplicationShortcutItemUserInfo(可選) 附加的信息
點(diǎn)擊快捷方式后方法的調(diào)用
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler API_AVAILABLE(ios(9.0)) {
NSLog(@"%s", __FUNCTION__);
if ([shortcutItem.type isEqualToString:@"search"]) {
NSLog(@"用戶從快捷方式“搜索”進(jìn)來(lái)的");
} else if ([shortcutItem.type isEqualToString:@"list"]) {
NSLog(@"用戶從快捷方式“榜單”進(jìn)來(lái)的");
} else if ([shortcutItem.type isEqualToString:@"public"]) {
NSLog(@"用戶從快捷方式“一鍵發(fā)布”進(jìn)來(lái)的");
}
}
(2)代碼創(chuàng)建快捷方式
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSLog(@"%s", __FUNCTION__);
if (@available(iOS 9.0, *)) {
// 其中的圖標(biāo)可以使用系統(tǒng)自定義,也可以使用項(xiàng)目中的
UIApplicationShortcutIcon *searchIcon = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeSearch];
UIApplicationShortcutItem *search = [[UIApplicationShortcutItem alloc] initWithType:@"search" localizedTitle:@"搜索" localizedSubtitle:nil icon:searchIcon userInfo:nil];
UIApplicationShortcutIcon *publicIcon = [UIApplicationShortcutIcon iconWithTemplateImageName:@"upload"];
UIApplicationShortcutItem *public = [[UIApplicationShortcutItem alloc] initWithType:@"public" localizedTitle:@"一鍵發(fā)布" localizedSubtitle:nil icon:publicIcon userInfo:nil];
UIApplicationShortcutItem *list = [[UIApplicationShortcutItem alloc] initWithType:@"list" localizedTitle:@"榜單" localizedSubtitle:@"全區(qū)排行" icon:nil userInfo:nil];
application.shortcutItems = @[list, public, search];
}
return YES;
}
點(diǎn)擊后觸發(fā)的方法和(1)一樣