SpotlightHandler 0.1.4

SpotlightHandler 0.1.4

测试测试过
Lang语言 Obj-CObjective C
许可证 MIT
发布最后发布2016年7月

Renato Matos维护。



在 Spotlight 搜索中索引您的应用程序的一种简单方法

0.1.4 更新

定义在索引搜索中使用的 App 图标。如果传递 "nil",则搜索将用 "AppIcon" 命名的图标进行索引

Pod

Podfile

pod "SpotlightHandler"

终端

pod install

用法

第一步是使您的 ViewController 成为 BaseIndexableViewController 的子类,如下所示

#import "BaseIndexableViewController.h"

@interface ViewController : BaseIndexableViewController


@end

这样,Spotlight 设置就已在 Interface Builder 中可见 alt tag

然后按照您偏好的方式填写字段

alt tag

(别忘了开启“Spot Indexable”字段) =)

AppDelegate

最后,在我们的 AppDelegate 类中添加一个方法,该方法将负责识别 Spotlight 的动作并显示选定的控制器

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler
{
    if ([userActivity.activityType isEqualToString:CSSearchableItemActionType]) {
        NSString *uniqueIdentifier = userActivity.userInfo[CSSearchableItemActivityIdentifier];

        [SpotlightHandler openController:uniqueIdentifier];
    }

    return YES;
}