您的位置:首页 > 移动开发 > IOS开发

iOS 9 spotlight搜索 3DTouch

2015-11-20 15:32 387 查看
1 spotlight搜索

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    

    [self
saveData];
}

- (void)saveData{

    

        NSMutableArray *seachableItems = [NSMutableArray
new];

    

        CSSearchableItemAttributeSet *attributeSet = [[CSSearchableItemAttributeSet
alloc]
initWithItemContentType:@"views"];

        attributeSet.title =
@"奇奇爱运动";

       // attributeSet.contentDescription = [NSString stringWithFormat:NSLocalizedString(@"a easy way to open %@", nil),@"objc"];

        UIImage *thumbImage = [UIImage
imageNamed:@"Icon_default"];

        attributeSet.thumbnailData =
UIImagePNGRepresentation(thumbImage);//beta 1 there is a bug

        CSSearchableItem *item = [[CSSearchableItem
alloc] initWithUniqueIdentifier:
@"奇奇爱运动"                                                                                         
                                          domainIdentifier:@"com.kdanmobile.CoreSpotlightDemo"                                                                                           
            attributeSet:attributeSet];

        [seachableItems addObject:item];

    

    [[CSSearchableIndex
defaultSearchableIndex] indexSearchableItems:seachableItems

                                                   completionHandler:^(NSError *
__nullable error) {                                                             
if (!error)

                                                      
NSLog(@"%@",error.localizedDescription);

                                                   }];

    //[CSSearchableIndex defaultSearchableIndex] deleteSearchableItemsWithIdentifiers: completionHandler:<#^(NSError * _Nullable error)completionHandler#>];

}

重写方法

- (BOOL)application:(nonnull
UIApplication *)application continueUserActivity:(nonnull
NSUserActivity *)userActivity restorationHandler:(nonnull
void (^)(NSArray *
__nullable))restorationHandler{

    

    NSString *idetifier = userActivity.userInfo[@"kCSSearchableItemActivityIdentifier"];

    

    UINavigationController *navigationController = (UINavigationController *)self.courseVC.navigationController;

    [navigationController popToRootViewControllerAnimated:YES];

    [self.courseVC
showWithNewAPP:idetifier];

    //[self.courseVC showAnAppDetailViewWithappKey:@"1040081628"];

    

    return
YES;

    

}

2 新特性 3DTouch

APPDelegate中重写方法即可

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

    NSString *type = shortcutItem.type;

    if ([type
isEqualToString:@"com.adc.itemSetting"]) {

        

        [self.courseVC
gotoSettingview];

    }else
if([type
isEqualToString:@"com.adc.itemSearch"]){

        

        [self.courseVC
showWithNewAPP:@"com.adc.itemFreeLimited"];

    }e

}

主页显示的quickly action 可以在info.plist 文件中自定义静态的 



也可以动态定义

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  

     UIApplicationShortcutItem *shortItem1 = [[UIApplicationShortcutItem alloc] initWithType:@"打开"
localizedTitle:@"打开"];

    UIApplicationShortcutItem *shortItem2 = [[UIApplicationShortcutItem alloc] initWithType:@"弹框" localizedTitle:@"弹框"];

    NSArray *shortItems = [[NSArray alloc] initWithObjects:shortItem1, shortItem2, nil];

    NSLog(@"%@", shortItems);

    [[UIApplication sharedApplication] setShortcutItems:shortItems];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: