Ios 从默认日历启动我的应用程序
我刚刚在iphone日历上添加了一个事件,代码如下:Ios 从默认日历启动我的应用程序,ios,objective-c,eventkit,Ios,Objective C,Eventkit,我刚刚在iphone日历上添加了一个事件,代码如下: EKEventStore *store=[[EKEventStore alloc] init]; [store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) { if (!granted) { return ; } EKEvent *ev
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);
}];
我的事件已添加到默认日历:
当您单击事件时,您将显示以下内容:
现在,我想从上面的屏幕之一启动我的应用程序。要注册自己的URL方案,Apple提供了一个很好的文档: 为此,请转到xcode项目文件并选择构建目标。 前往“信息”。在底部有一个“URL类型”下拉列表。 该标识符可能与您为包标识符获得的标识符相匹配。方案本身非常重要,在这里输入一个方案,稍后使用。例如:“myCustomScheme” 现在将应用程序带到设备上,并提供以下链接: 我的习俗cheme://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;
}
不要使用谷歌url,而是使用你的应用注册的方案指定一个。使用url方案试试你可以使用它打开你的应用。你可以传递任何你想传递的内容,但使用自定义方案。例如,不要“使用”我的习惯cheme://google.com". 如果您想从日历中打开应用程序,我希望应用程序能够处理我选择的正确事件。因此,您可以传递事件的ID或日期。“我的海关cheme://08-04-2014/“谢谢你@Lepidopternon,它帮助了我,现在我也想申请签证。这意味着我想启动iPhone的默认日历应用程序,那么我应该怎么做?要回去,你可以使用“calshow://”方案,在这个线程中描述:是的,它可以工作。但是,如果我想用特定EKEvent的对象打开日历,那么我应该做什么呢?关于:可以创建日历事件,但不能直接在日历中打开它们。我很抱歉。