美文网首页
3D Touch----shortcutItems

3D Touch----shortcutItems

作者: 笑看人生_44e2 | 来源:发表于2021-05-25 11:10 被阅读0次
    • (BOOL)application:(UIApplication *)application WechatIMG781.png
    WechatIMG782.png

    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
    [self creatShortcutItem];
    if(launchOptions){
    if([[[UIDevice currentDevice] systemVersion] doubleValue]>=9.0){
    UIApplicationShortcutItem *shortcutItem = [launchOptions valueForKey:UIApplicationLaunchOptionsShortcutItemKey];
    if (shortcutItem) {
    //判断先前我们设置的快捷选项标签唯一标识,根据不同标识执行不同操作
    [self dealWithShortcut:shortcutItem.type];
    return NO;
    }
    }
    }
    // 广告
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"adsstatus"] intValue] ==1) {
    [self creadeADView];
    }
    return YES;
    }

    pragma mark - 3D Touch 创建 shortcutItem

    • (void)creatShortcutItem {
      //创建系统风格的icon
      // UIApplicationShortcutIcon *icon = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeShare];

      // 自定义icon,大小为 70*70 px
      UIApplicationShortcutIcon *payIcon = [UIApplicationShortcutIcon iconWithTemplateImageName:@"item_scp"];
      UIApplicationShortcutItem *payItem = [[UIApplicationShortcutItem alloc]initWithType:@"item_scp" localizedTitle:@"搜菜谱" localizedSubtitle:nil icon:payIcon userInfo:nil];

      UIApplicationShortcutIcon *scanIcon = [UIApplicationShortcutIcon iconWithTemplateImageName:@"item_xal"];
      UIApplicationShortcutItem *scanItem = [[UIApplicationShortcutItem alloc]initWithType:@"item_xal" localizedTitle:@"学案例" localizedSubtitle:nil icon:scanIcon userInfo:nil];

      UIApplicationShortcutIcon *qrcodeIcon = [UIApplicationShortcutIcon iconWithTemplateImageName:@"item_kzz"];
      UIApplicationShortcutItem *qrcodeItem = [[UIApplicationShortcutItem alloc]initWithType:@"item_kzz" localizedTitle:@"看杂志" localizedSubtitle:nil icon:qrcodeIcon userInfo:nil];

      UIApplicationShortcutIcon *redpackIcon = [UIApplicationShortcutIcon iconWithTemplateImageName:@"item_fqz"];
      UIApplicationShortcutItem *redpackItem = [[UIApplicationShortcutItem alloc]initWithType:@"item_fqz" localizedTitle:@"发圈子" localizedSubtitle:nil icon:redpackIcon userInfo:nil];

      //添加到快捷选项数组
      [UIApplication sharedApplication].shortcutItems = @[payItem,scanItem,qrcodeItem,redpackItem];
      }

    pragma mark - 当app已启动, 点击shortcutItem回调

    • (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler {
      NSLog(@"快捷方式 : %@",shortcutItem.type);
      [self dealWithShortcut:shortcutItem.type];
      completionHandler(YES);
      }
    • (void)dealWithShortcut:(NSString*)type {
      NSLog(@"dealWithShortcut = %@",type);
      [[NSUserDefaults standardUserDefaults]setObject:type forKey:@"shortType"];
      [[NSUserDefaults standardUserDefaults]synchronize];
      [[NSNotificationCenter defaultCenter] postNotificationName:@"shortcutItem" object:nil];

    }
    -(void)creadeADView{
    }

    相关文章

      网友评论

          本文标题:3D Touch----shortcutItems

          本文链接:https://www.haomeiwen.com/subject/gyvciktx.html