一、配置菜单项的方式
要求:6s(系统版本号大于9.0)及以上机器可用,最多配置4个菜单
1.在info.plist里面配置;缺点:配置的菜单图片只能是系统默认的20多种,优点:安装好应用后不需要启动就有长按菜单了
plist文件配置暂不介绍
2.在启动方法里面手动添加;优点:可以自己配置菜单的图片(只要包里面存在图片即可)缺点:需要启动一次之后才能有长按菜单
-(void)create3DItems{
if ([[[UIDevice currentDevice] systemVersion]floatValue] >= 9.1){// 自定义图标UIApplicationShortcutIcon *icon1 = [UIApplicationShortcutIcon iconWithTemplateImageName:@"cib_login_edit_blue.png"];
UIApplicationShortcutItem *shortItem1 = [[UIApplicationShortcutItem alloc] initWithType:@"com.cibmb.dev.zzhk" localizedTitle:@"转账汇款" localizedSubtitle:@"子标题1" icon:icon1 userInfo:nil];
UIApplicationShortcutItem *shortItem2 = [[UIApplicationShortcutItem alloc] initWithType:@"com.cibmb.dev.ewm" localizedTitle:@"二维码付款" localizedSubtitle:@"子标题2" icon:[UIApplicationShortcutIcon iconWithType: UIApplicationShortcutIconTypeCompose] userInfo:nil];
UIApplicationShortcutItem *shortItem3 = [[UIApplicationShortcutItem alloc] initWithType:@"com.cibmb.dev.zhcx" localizedTitle:@"账户查询" localizedSubtitle:@"子标题3" icon:[UIApplicationShortcutIcon iconWithType: UIApplicationShortcutIconTypeTaskCompleted] userInfo:nil];
UIApplicationShortcutItem *shortItem4 = [[UIApplicationShortcutItem alloc] initWithType:@"com.cibmb.dev.ayrs" localizedTitle:@"安愉人生" localizedSubtitle:@"子标题4" icon:[UIApplicationShortcutIcon iconWithType: UIApplicationShortcutIconTypeLocation] userInfo:nil];
// item 数组
NSArray *shortItems = [[NSArray alloc] initWithObjects:shortItem1,shortItem2,shortItem3,shortItem4, nil];
// 设置菜单数组
[[UIApplication sharedApplication] setShortcutItems:shortItems];
}
}
二、菜单点击方法
此处注意与推送的区别,因为通过点击菜单启动app或者点击菜单让app从后台回到前台,都会走这个方法
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^) (BOOL))completionHandler {
//判断先前我们设置的快捷选项标签唯一标识,根据不同标识执行不同操作 [self gotoTouchDetailView:shortcutItem.type];
}
网友评论