[英]iOS - Add custom URI of our app to the event stored in calendar programmatically
i have a scenario where i am adding the event in calendar from my application. 我有一种情况,我将从我的应用程序在日历中添加事件。 i have a custom url scheme for my app as myapp:// 我为我的应用程序添加了一个自定义网址方案,例如myapp://
the code i am using to store the event in calendar is 我用来在日历中存储事件的代码是
-(void)addEventToCalender
{
NSDateComponents *components = [[NSDateComponents alloc]init];
[components setYear:2014];
[components setMonth:6];
[components setDay:15];
[components setHour:10];
[components setMinute:15];
NSCalendar *cal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *eventDateAndTime = [cal dateFromComponents:components];
NSLog(@"Event Date and Time : %@",eventDateAndTime);
EKEventStore *store = [[EKEventStore alloc]init];
EKEvent *event = [EKEvent eventWithEventStore:store];
event.title = @"ttrrpp Trip";
event.notes = @"Go to application myapp://";
event.startDate = eventDateAndTime;
event.endDate = [[NSDate alloc]initWithTimeInterval:600 sinceDate:eventDateAndTime];
[store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)
{
if (granted)
{
[event setCalendar:[store defaultCalendarForNewEvents]];
NSError *err = nil;
[store saveEvent:event span:EKSpanThisEvent commit:YES error:&err];
NSString *savedEventId = event.eventIdentifier;
NSLog(@"Saved Event ID : %@",savedEventId);
}
else
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"ttrrpp" message:@"You have denied to provide access to calender. No events will be added." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
}];
} }
The event is added in calendar but i want to pass the url of my app to the notes so that it opens my app when the link in event notes is clicked. 该事件已添加到日历中,但是我想将我的应用程序的URL传递给笔记,以便在单击事件笔记中的链接时打开我的应用程序。 Kindly help me. 请帮助我。 Thanks in advance. 提前致谢。
You are very close ;-) . 您非常亲近;-)。 Assuming you have defined your custom URL scheme in your .plist, add a 'host' and 'path' to your custom URL scheme being placed in event.notes. 假设您已在.plist中定义了自定义URL方案,则将“ host”和“ path”添加到放置在event.notes中的自定义URL方案中。 (eg. myapp://myhost/mypath) Then something like... (例如myapp:// myhost / mypath)然后类似...
-(BOOL)application:(UIApplication*)application handleOpenURL:(NSURL*)url { - deprecated
-(BOOL) application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
if (!url) {
return NO;
}
if([[url host] isEqualToString:@"myhost"])
{
//can also check [url path] if you want to
//do whatever
}
return YES;
}
PS: deprecated method worked for me with iOS6/7, haven't tried new method. PS:不推荐使用的方法在iOS6 / 7上对我有用,还没有尝试过新方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.