1褥实、創(chuàng)建3DTouch的兩種方式
- 靜態(tài)標(biāo)簽
靜態(tài)標(biāo)簽是我們?cè)陧?xiàng)目的配置plist文件中配置的標(biāo)簽呀狼,在用戶安裝程序后就可以使用,并且排序會(huì)在動(dòng)態(tài)標(biāo)簽的前面损离。
首先哥艇,在info.plist文件中添加了一個(gè)UIApplicationShortcutItems的數(shù)組,這個(gè)數(shù)組中添加的元素就是對(duì)應(yīng)的靜態(tài)標(biāo)簽僻澎,在每個(gè)標(biāo)簽中我們需要添加一些設(shè)置的鍵值:
必填項(xiàng)(下面兩個(gè)鍵值是必須設(shè)置的):
這個(gè)鍵值設(shè)置一個(gè)快捷通道類型的字符串
UIApplicationShortcutItemType
這個(gè)鍵值設(shè)置標(biāo)簽的標(biāo)題
UIApplicationShortcutItemTitle
選填項(xiàng)(下面這些鍵值不是必須設(shè)置的):
設(shè)置標(biāo)簽的副標(biāo)題
UIApplicationShortcutItemSubtitle
設(shè)置標(biāo)簽Icon類型
UIApplicationShortcutItemIconType
設(shè)置標(biāo)簽的Icon文件
UIApplicationShortcutItemIconFile
設(shè)置信息字典(用于傳值)
UIApplicationShortcutItemUserInfo
- 動(dòng)態(tài)標(biāo)簽
注意事項(xiàng):使用之前一定要判斷設(shè)備和系統(tǒng)是否支持貌踏,否則會(huì)崩潰
- (void)add3DTouch{
//判斷設(shè)備是否支持
if (([UIDevice currentDevice].systemVersion.floatValue > 9.0) && (self.window.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable)) {
//添加3DTouch item
UIApplicationShortcutIcon *stockIcon = [UIApplicationShortcutIcon iconWithTemplateImageName:@"xxx"];
UIApplicationShortcutIcon *inventoryIcon = [UIApplicationShortcutIcon iconWithTemplateImageName:@"yay"];
UIApplicationShortcutItem *stockOutItem = [[UIApplicationShortcutItem alloc]initWithType:@"stockout" localizedTitle:@"xxx" localizedSubtitle:nil icon: stockIcon userInfo:nil];
UIApplicationShortcutItem *inventoryItem = [[UIApplicationShortcutItem alloc]initWithType:@"inventory" localizedTitle:@"yyy" localizedSubtitle:nil icon:inventoryIcon userInfo:nil];
[UIApplication sharedApplication].shortcutItems = @[inventoryItem,stockOutItem];
}
}