在启动页进行操作
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
初始化3D-touch
application.applicationSupportsShakeToEdit =YES;
struct utsname systemInfo;
uname(&systemInfo);
NSString *deviceString = [NSStringstringWithCString:systemInfo.machineencoding:NSUTF8StringEncoding];
if ([deviceString isEqualToString:@"iPhone8,1"] || [deviceStringisEqualToString:@"iPhone8,2"]) {
[selfconfigShortCutItems];
}
return YES;
}
#pragma mark -3d Touch打开
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.windowendEditing:YES];
}
/** 创建shortcutItems */
- (void)configShortCutItems {
NSMutableArray *shortcutItems = [NSMutableArrayarray];
UIApplicationShortcutItem *item1 = [[UIApplicationShortcutItemalloc] initWithType:@"1"localizedTitle:@"预约挂号"localizedSubtitle:nilicon:[UIApplicationShortcutIconiconWithTemplateImageName:@"icon_register55.png"]userInfo:nil];
UIApplicationShortcutItem *item2 = [[UIApplicationShortcutItemalloc] initWithType:@"2"localizedTitle:@"当天挂号"localizedSubtitle:nilicon:[UIApplicationShortcutIconiconWithTemplateImageName:@"icon_same-day13.png"]userInfo:nil];
[shortcutItems addObject:item1];
[shortcutItems addObject:item2];
[[UIApplicationsharedApplication] setShortcutItems:shortcutItems];
}
/** 处理shortcutItem */
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler {
switch (shortcutItem.type.integerValue) {
case 1: {
[[NSNotificationCenterdefaultCenter] postNotificationName:@"gotoVc"object:selfuserInfo:@{@"type":@"1"}];
break;
}
case 2: {
[[NSNotificationCenterdefaultCenter] postNotificationName:@"gotoVc"object:selfuserInfo:@{@"type":@"2"}];
break;
}
default:
break;
}
}
在展示页面操作
初始化通知
- (void)viewDidLoad {
[[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(gotoVc:)name:@"gotoVc"object:nil];
}
#pragma mark 通知相关
- (void)dealloc {
[[NSNotificationCenterdefaultCenter] removeObserver:self];
}
处理通知
- (void)gotoVc:(NSNotification *)noti {
NSString *type = noti.userInfo[@"type"];
DH_AppointmentController *appointMent = [[DH_AppointmentControlleralloc] init];
if ([type isEqualToString:@"1"]) {
appointMent.whiceTag = @"0";
[self.navigationControllerpushViewController:appointMent animated:YES];
} else if ([typeisEqualToString:@"2"]) {
appointMent.whiceTag = @"1";
[self.navigationControllerpushViewController:appointMent animated:YES];
}
}
小结:此技术不难掌握,但由于刚出来,资料不是很多,掌握这三步,基本可以解决问题。