简体   繁体   English

如何从Spotlight搜索中启动该应用程序?

[英]How to get that application launch from spotlight search?

I have implemented spotlight search in my application, Everything is working fine, But in some situation I want to require to know that application launch from spotlight search or not ? 我已经在我的应用程序中实现了Spotlight搜索,一切正常,但是在某些情况下,我想要求知道应用程序是否从Spotlight搜索启动? please help me how can I know this. 请帮我如何知道这一点。

AppDelegate.m AppDelegate.m

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void(^)(NSArray *restorableObjects))restorationHandler{
    self.isSportlight = YES;
    self.strSportlightUnitname = [userActivity.userInfo valueForKey:@"kCSSearchableItemActivityIdentifier"];
    return YES;
}

rootViewcontroller.m rootViewcontroller.m

- (void)viewDidLoad
{
   if(!appDel.isSportlight){
        [self OnLaunchSettings];
    }else{
         [self setupSportLightEvent];
    }
}

Aspected result is appDel.isSportlight = TRUE But appDel.isSportlight always got FALSE because "continueUserActivity:(NSUserActivity *)userActivity restorationHandler" method call after "ViewDidLoad" 方面的结果是appDel.isSportlight = TRUE,但是appDel.isSportlight始终为FALSE,因为在“ ViewDidLoad”之后调用了“ continueUserActivity:(NSUserActivity *)userActivity restoreHandler”方法

The root view controller shouldn't be checking in with the app delegate, that relationship is the wrong way round. 根视图控制器不应该使用应用程序委托进行签入,这种关系是错误的处理方式。 The app delegate should be telling the root view controller (or possibly posting a global notification if other controllers need to know about it) so that it can respond at any time, not just when it's initially setting things up. 应用程序委托应该告诉根视图控制器(如果其他控制器需要知道它,则可以发布全局通知),以便它可以在任何时间响应,而不仅仅是在最初进行设置时。 You need to write your code so that you can switch between different states. 您需要编写代码,以便可以在不同状态之间切换。 That would usually be done by pushing or adding/removing child view controllers so you compartmentalise the functionality of each mode. 通常,这可以通过推入或添加/删除子视图控制器来完成,这样就可以分隔每种模式的功能。

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

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