您的位置:首页 > 移动开发 > IOS开发

3D touch

2015-12-01 15:59 405 查看
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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios 3D Touch