用于打开具有特定日期的本地日历的 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 scheme,找到了方法.主要有两点:
I played with this url scheme a little and found the way to do it. The main two points are:
- 不要在
calshow:
之后使用//" - 自参考日期(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:
不是公共 url 方案,因此 Apple 可能会不赞成以这种方式使用它.或者也许他们不会(我还没有研究过).
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屋!