ios - 3D 触摸主屏幕操作,Launchoptions 始终为零,即使从

标签 ios iphone 3dtouch

启动选项始终为零。

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    //Launch options is always coming nil 
   //even when I launch from 3D touch shortcut icon
     shortcutItemkey = [launchOptions objectForKey:UIApplicationLaunchOptionsShortcutItemKey];

 return N0;
        }

performActionForShortcutItem 委托(delegate)方法照常被调用。

-(void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL succeeded))completionHandler {

    completionHandler([self handleShortcut:shortcutItem]);

}

最佳答案

- (void)shortcutsWithIcon
{
@try 
{
   UIApplicationShortcutIcon *icon1 = [UIApplicationShortcutIcon iconWithTemplateImageName:@"img_editProduct"];
   UIApplicationShortcutIcon *icon2 = [UIApplicationShortcutIcon iconWithTemplateImageName:@"img_Classifieds"];

   UIMutableApplicationShortcutItem *item1 = [[UIMutableApplicationShortcutItem alloc]initWithType:@"com.3dtouchApp.postAnItem" localizedTitle:@"Post an Item" localizedSubtitle:@"Add new product for sale" icon:icon1 userInfo:nil];
   UIMutableApplicationShortcutItem *item2 = [[UIMutableApplicationShortcutItem alloc]initWithType:@"com.3dtouchApp.LatestAds" localizedTitle:@"Latest Ads" localizedSubtitle:@"View top recent Ads" icon:icon2 userInfo:nil];
   NSArray *items = @[item2, item1];

   [UIApplication sharedApplication].shortcutItems = items;
}
@catch (NSException *exception) {

}
}


 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
   if (self.window.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable)
   {
     [self shortcutsWithIcon];
 UIApplicationShortcutItem *item = [launchOptions valueForKey:UIApplicationLaunchOptionsShortcutItemKey];
        if (item) {
            NSLog(@"We've launched from shortcut item: %@", item.localizedTitle);
        } else {
            NSLog(@"We've launched properly.");
        }
     if ([item.type isEqualToString:@"com.3dtouchApp.postAnItem"])
     {
       ***//Code for launch your screen***
     }

     if ([item.type isEqualToString:@"com.3dtouchApp.LatestAds"])
     {
        ***//code for launch your screen***
     }
    }
  return YES;
}
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler
{
    if ([shortcutItem.type isEqualToString:@"com.3dtouchApp.LatestAds"]) 
    {
      ***//Code for launch your screen***
     }
     if ([shortcutItem.type isEqualToString:@"com.3dtouchApp.postAnItem"]) 
     {
       ***//Code for launch your screen***
     }

}

关于ios - 3D 触摸主屏幕操作,Launchoptions 始终为零,即使从,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35124210/

相关文章:

ios - 什么是新 iPhone 的透视和流行力量?

ios - Swift XMLMapper 解码嵌套属性

iOS释放内存问题

iphone - 没有边框的圆角矩形 UIButton

iphone - iOS:AFNetworking:如果 token 过期则重复 block

ios - 适用于 iPhone XR 和 iPhone XS 的 Peek 和 Pop

ios - 静音 3D 触摸 快速操作

ios - 从 Nib 加载 UITableViewCell 子类时给出错误的类型

ios - 如何快速获取当前订阅的用户收据

iphone - 检查 iPhone 中的来电