【iOS】3D Touch开发

一、Home Screen Quick Actions

第一,你得有个6s手机!

如果没有,也可以!

根据此链接教程,在模拟器上开发

1.添加静态标签:在info.plist中添加数组字段:UIApplicationShortcutItems。(其中每个item都是一个标签,将item设置为字典属性。)

2.为每个item设置属性:

a).必设

UIApplicationShortcutItemType 标签的标识,用来区分点击的标签。
UIApplicationShortcutItemTitle 为标签设置标题

b).可选

UIApplicationShortcutItemSubtitle 为标签设置副标题
UIApplicationShortcutItemIconType 设置标签Icon类型
UIApplicationShortcutItemIconFile 设置标签Icon图片
UIApplicationShortcutItemUserInfo 设置标签信息字典

3.动态添加标签

UIMutableApplicationShortcutItem *codeItem = [[UIMutableApplicationShortcutItem alloc] initWithType:k3DTouch_OrderCode_Type localizedTitle:[NSString stringWithFormat:@"收货码:%@", [self.viewModel achiveLastestCode]]];
      codeItem.localizedSubtitle = [NSString stringWithFormat:@"%@,消费%.2f元", [self.viewModel achiveShopName], [self.viewModel achivePrice] / 100.];
      
NSArray *addArr = @[codeItem];
[UIApplication sharedApplication].shortcutItems = addArr;

4.处理点击事件

4.1 启动程序

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  
  if (launchOptions) {
    
    id identifier = [launchOptions objectForKey:UIApplicationLaunchOptionsShortcutItemKey];
    
    // 3D Touch
    if (identifier) {
      UIApplicationShortcutItem *aItem = identifier;
      [LLCPlistManager config3DTouch:aItem.type];
    }
  }

......
}

4.2 唤醒程序(此前在后台运行)

- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler {
  if (shortcutItem) {
    if ([shortcutItem.type isEqual:k3DTouch_Order_Type]) {
      [kNotificationCenter postNotificationName:LLC3DTouch_CheckOrder object:nil];
    } else if ([shortcutItem.type isEqual:k3DTouch_Shop_Type]) {
      [kNotificationCenter postNotificationName:LLC3DTouch_CheckShop object:nil];
    } else if ([shortcutItem.type isEqualToString:k3DTouch_OrderCode_Type]) {
      [kNotificationCenter postNotificationName:LLC3DTouch_CheckShop object:nil];
    }
  }
}

你可能感兴趣的:(【iOS】3D Touch开发)