在App启动后,添加3DTouch的快捷入口,代码如下:
NSMutableArray *arrShortcutItem = (NSMutableArray *)[UIApplication sharedApplication].shortcutItems;
NSArray *typeArr = @[@"com.zhang.xxx.addOil",@"com.zhang.xxx.daijia",@"com.zhang.xxx.huafei"];
UIApplicationShortcutItem *shoreItem1 = [[UIApplicationShortcutItem alloc] initWithType:[typeArr indexs:0] localizedTitle:@"立即加油" localizedSubtitle:nil icon:[UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeCompose] userInfo:nil];
[arrShortcutItem addObject:shoreItem1];
UIApplicationShortcutItem *shoreItem2 = [[UIApplicationShortcutItem alloc] initWithType:[typeArr indexs:1] localizedTitle:@"代驾服务" localizedSubtitle:nil icon:[UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeCompose] userInfo:nil];
[arrShortcutItem addObject:shoreItem2];
UIApplicationShortcutItem *shoreItem3 = [[UIApplicationShortcutItem alloc] initWithType:[typeArr indexs:2] localizedTitle:@"话费充值" localizedSubtitle:nil icon:[UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeCompose] userInfo:nil];
[arrShortcutItem addObject:shoreItem3];
[UIApplication sharedApplication].shortcutItems = arrShortcutItem;
苹果爸爸有个bug,可能会重复添加item,解决方法:添加item之前,判断下已有item是否存在,存在就删除,代码如下:
NSArray *typeArr = @[@"com.zhang.weoil.addOil",@"com.zhang.weoil.daijia",@"com.zhang.weoil.huafei"];
NSArray *tempArr = [NSArray arrayWithArray:arrShortcutItem];
for (UIApplicationShortcutItem *item in tempArr) {
if ([typeArr containsObject:item.type]) {
[arrShortcutItem removeObject:item];
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)