gpt4 book ai didi

iOS - 以编程方式将我们应用程序的自定义 URI 添加到存储在日历中的事件

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:04:38 26 4
gpt4 key购买 nike

我有一个场景,我从我的应用程序中将事件添加到日历中。我的应用程序有一个自定义 url 方案,如 myapp://

我用来在日历中存储事件的代码是

-(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];
}
}];

事件已添加到日历中,但我想将我的应用程序的 url 传递给笔记,以便在单击事件笔记中的链接时打开我的应用程序。请帮助我。提前致谢。

最佳答案

你们非常亲密 ;-) 。假设您已在 .plist 中定义了自定义 URL 方案,请将“主机”和“路径”添加到放置在 event.notes 中的自定义 URL 方案。 (例如 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:已弃用的方法适用于我的 iOS6/7,还没有尝试过新方法。

关于iOS - 以编程方式将我们应用程序的自定义 URI 添加到存储在日历中的事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24179018/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com