用于打开具有特定日期的本机日历的URL方案 [英] URL scheme for opening native calendar with specific date
问题描述
我已经找到示例代码,从我的应用打开日历,但我无法在特定日期打开。
I have found the sample code to open calendar from my app, but i can't open at a specific date.
NSString* launchUrl = @"calshow://";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: launchUrl]];
有一种方法可以在lunchUrl字符串的末尾添加特定日期,
Is there a way to add specific date at the end of the "lunchUrl" string so when the user opens the calendar it displays the given date.
我已经尝试过以下格式:@calshow://?= 2013 12 19,@calshow: /?= 2013-12-19,@calshow://?= 2013 + 12 + 19。这些都不适合我...任何想法我做错了什么?
I have already tried the following formats: @"calshow://?=2013 12 19", @"calshow://?=2013-12-19", @"calshow://?=2013+12+19". None of these seem to work for me... any ideas what am i'm doing wrong?
推荐答案
url方案一点,找到了办法做到。主要两点是:
I played with this url scheme a little and found the way to do it. The main two points are:
- 不要在
calshow:$ c之后使用// $ c>
- 自参考日期(2001年1月1日)起通过时间戳记
代码:
- (void)showCalendarOnDate:(NSDate *)date
{
// calc time interval since 1 January 2001, GMT
NSInteger interval = [date timeIntervalSinceReferenceDate];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"calshow:%ld", interval]];
[[UIApplication sharedApplication] openURL:url];
}
这就是我所说的:
// create some date and show the calendar with it
- (IBAction)showCalendar:(id)sender
{
NSDateComponents *comps = [[NSDateComponents alloc] init];
[comps setDay:4];
[comps setMonth:7];
[comps setYear:2010];
NSCalendar *cal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
[self showCalendarOnDate:[cal dateFromComponents:comps]];
}
也许你应该考虑 calshow: / code>不是一个公共网址方案,所以也许苹果会皱着眉头这样使用它。或者也许他们不会(我没有研究过)。
Perhaps you should take into account that calshow:
is not a public url scheme, so maybe Apple would frown upon using it in this way. Or maybe they wouldn't (I haven't researched that).
这篇关于用于打开具有特定日期的本机日历的URL方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!