3D触摸主屏幕动作,即使进入后,Launchoptions也始终为零

时间:2016-02-01 06:27:21

标签: 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委托方法正常被调用。

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

    completionHandler([self handleShortcut:shortcutItem]);

}

1 个答案:

答案 0 :(得分:1)

- (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***
     }

}