- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if (IOS9_OR_LATER) {
[self shortCut];
}
}
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void(^)(BOOL succeeded))completionHandler
{
if ([shortcutItem.type isEqualToString:@"searchItem"]) {
SearchViewController *room = [[SearchViewController alloc] init];
[baseNav pushViewController:room animated:YES];
}
if ([shortcutItem.type isEqualToString:@"icon_recharge"]) {
RechargeViewController *room = [[RechargeViewController alloc] init];
[baseNav pushViewController:room animated:YES];
}
}
//3d touch screen short cut
- (void) shortCut
{
NSArray * typeArray =@[@"searchItem",@"rechargeItem"];//key类型
NSArray * titleArray = @[@"搜索",@“充值”];//标题
//图标名字,项目资源中的图标名称
NSArray * imageNameArray =@[@"icon_search",@"icon_recharge"];
NSMutableArray * itemArray = [[NSMutableArray alloc] init];
for (int i=0; i<typeArray.count; i++) {
UIApplicationShortcutIcon * icon = [UIApplicationShortcutIcon iconWithTemplateImageName:imageNameArray[i]];
UIMutableApplicationShortcutItem * item = [[UIMutableApplicationShortcutItem alloc] initWithType:typeArray[i] localizedTitle:titleArray[i] localizedSubtitle:@"" icon:icon userInfo:nil];
[itemArray addObject:item];
}
[UIApplication sharedApplication].shortcutItems = itemArray;
}