从默认日历启动我的应用程序

我从下面的代码刚刚在iPhone日历上添加了一个事件:

EKEventStore *store=[[EKEventStore alloc] init]; [store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) { if (!granted) { return ; } EKEvent *event=[EKEvent eventWithEventStore:store]; event.title=@"This is the event"; event.startDate=[NSDate date]; event.endDate =[event.startDate dateByAddingTimeInterval:60*60]; event.allDay=YES; NSURL *url=[NSURL URLWithString:@"http://www.google.com"]; event.URL=url; [event setCalendar:[store defaultCalendarForNewEvents]]; NSError *errr=nil; [store saveEvent:event span:EKSpanThisEvent commit:YES error:&errr]; // NSLog(@"%@",errr); // NSLog(@"%@",event.eventIdentifier); }]; 

我的活动已添加到默认日历中: 在这里输入图像说明

当你点击事件时,你会显示这个: 在这里输入图像说明

现在我想从上面的屏幕之一启动我的应用程序。

要注册自己的URLscheme,Apple提供了一个很好的文档: https : //developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AdvancedAppTricks/AdvancedAppTricks.html#//apple_ref/doc/uid/TP40007072 -CH7-SW50

为此,请转到您的xcode-Project文件并select构build目标。 前往“信息”。 底部有一个“urltypes”的下拉菜单。 标识符可以匹配你的标识符。 这个计划本身是相当重要的,在这里你input一个,你会稍后使用。 例如:“myCustomScheme” 在这里输入图像说明

现在将该应用程序放在设备上,并提供如下链接:myCustomScheme:// additionalURLWithcustomInformation /?andParametersYouWantToUseLater = 1234

现在在AppDelegate中实现以下方法并处理事件:

 - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { if ([[url scheme] isEqualToString:@"myCustomScheme"]) { // Custom URL handling, for example for url parameters } return YES; }