在
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
方法里面判斷,該手機(jī)是否是9.0以上,因?yàn)?dtouch是9.0以后出的功能
CGFloat currentDeviceVersionFloat = [[[UIDevice currentDevice] systemVersion] floatValue];
//判斷版本號(hào),3D Touch是從iOS9.0后開(kāi)始使用
if (currentDeviceVersionFloat >= 9.0) {
[self addThreeDTouchAction:application]; // 在此方法里面添加3d touch 桌面cell
}
- (void)addThreeDTouchAction:(UIApplication *)application{
UIApplicationShortcutIcon *sys = [UIApplicationShortcutIcon iconWithType:<#(UIApplicationShortcutIconType)#>];// 使用此方法,可以調(diào)用系統(tǒng)默認(rèn)的圖標(biāo)
//以下為自定義?
UIApplicationShortcutIcon *iconLottery = [UIApplicationShortcutIcon iconWithTemplateImageName:@"server_lottery"];
/// 3d touch開(kāi)獎(jiǎng)大廳 按鈕創(chuàng)建
UIMutableApplicationShortcutItem *itemLottery = [[UIMutableApplicationShortcutItem alloc] initWithType:ThreeDTouchTypeLottery localizedTitle:@"開(kāi)獎(jiǎng)大廳"];// 指定標(biāo)題
itemLottery.icon = iconLottery; // 指定圖標(biāo)
itemLottery.localizedSubtitle = @"開(kāi)獎(jiǎng)全網(wǎng)最快";// 指定子標(biāo)題
UIApplicationShortcutIcon *iconGold = [UIApplicationShortcutIcon iconWithTemplateImageName:@"server_gold"];
/// 3d touch開(kāi)獎(jiǎng)大廳 按鈕創(chuàng)建
UIMutableApplicationShortcutItem *itemGold = [[UIMutableApplicationShortcutItem alloc] initWithType:ThreeDTouchTypeGold localizedTitle:@"比分賽果"];
itemGold.icon = iconGold;
itemGold.localizedSubtitle = @"比分信息最全";
/// 3d touch開(kāi)獎(jiǎng)大廳 按鈕創(chuàng)建
UIApplicationShortcutIcon *iconFriend = [UIApplicationShortcutIcon iconWithTemplateImageName:@"tabbar_find_normal"];
UIMutableApplicationShortcutItem *itemFriend = [[UIMutableApplicationShortcutItem alloc] initWithType:ThreeDTouchTypeFriend localizedTitle:@"身邊彩友"];
itemFriend.icon = iconFriend;
itemFriend.localizedSubtitle = @"尋找身邊的彩友";
application.shortcutItems = @[itemLottery,itemGold,itemFriend];
}
// 在此方法里面添加你的操作
- (void)application:(UIApplication *)application performActionForShortcutItem:(nonnull UIApplicationShortcutItem *)shortcutItem completionHandler:(nonnull void (^)(BOOL))completionHandler;
注:
// 當(dāng)項(xiàng)目上線,系統(tǒng)會(huì)默認(rèn)添加分享的功能
// UIApplicationShortcutIconType 的類(lèi)型校對(duì)表