繁体   English   中英

3D触摸主屏幕操作,即使从

[英]3D touch home screen actions, Launchoptions is nil always even after entering from

启动选项始终为零。

    - (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]);

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

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM