1. 静态配置
直接在info.list文件里面配置就好了
然后在AppDelegate内实现 UIApplicationDelegate 代理的一个函数
-(void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler
{
NSLog(@"type = %@",shortcutItem.type); //依据type 可以判断点击的是什么操作
NSLog(@"dict = %@",shortcutItem.userInfo);
}
2. 动态配置
完全不需要在info.list里面配置
直接在AppDelegate里面
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//替换
// NSArray <UIApplicationShortcutItem *> *existingShortcutItems = [[UIApplication sharedApplication] shortcutItems];
// UIApplicationShortcutItem *anExistingShortcutItem = [existingShortcutItems objectAtIndex: anIndex];
// NSMutableArray <UIApplicationShortcutItem *> *updatedShortcutItems = [existingShortcutItems mutableCopy];
// UIMutableApplicationShortcutItem *aMutableShortcutItem = [anExistingShortcutItem mutableCopy];
// [aMutableShortcutItem setLocalizedTitle: @"New Title"];
// [updatedShortcutItems replaceObjectAtIndex: anIndex withObject: aMutableShortcutItem];
// [[UIApplication sharedApplication] setShortcutItems: updatedShortcutItems];
//动态添加
UIApplicationShortcutIcon *icon1 = [UIApplicationShortcutIcon iconWithTemplateImageName:@"b1"];//图片名称
UIApplicationShortcutItem *item1 = [[UIApplicationShortcutItem alloc] initWithType:@"a" localizedTitle:@"AAA" localizedSubtitle:nil icon:icon1 userInfo:nil];
[[UIApplication sharedApplication] setShortcutItems:@[item1]];
return YES;
}
3D touch
最新推荐文章于 2022-04-01 16:10:57 发布