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];
}
- (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];
}
相关文章推荐
- iOS 时间格式转化合集
- IOS开发过程中的变量命名规范和图片及切图命名规范
- iOS深入学习(使用CocoaPods进行第三方资源管理)
- iOS NSDecimalNumber 货币计算 四舍五入
- iOS CocoaPods安装和使用图解
- iOS移动开发CoreDate讲解
- IOS沙盒机制(SandBox)
- iOS 音乐 锁屏显示 控制
- iOS 8 AutoLayout与Size Class自悟
- iOS-----MFMessageCompose 和 MFMailComposeViewController的使用方法
- IOS版OpenGL游戏引擎的集成KeyMob管理库教程
- iOS 中文转拼音
- iOS NSString的常用用法
- iOS 中 new 和 alloc init 的区别
- IOS静态库和Framework区别
- ios 键盘遮挡输入框解决方法
- 华硕笔记本刷BIOS
- cocoa框架 for iOS
- iOS 事件处理机制与图像渲染过程
- ios 真机调试打包等