用于打开具有特定日期的本机日历的URL方案

And*_*nor 13 icalendar cocoa-touch calendar objective-c

我找到了从我的应用程序打开日历的示例代码,但我无法在特定日期打开.

NSString* launchUrl = @"calshow://";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: launchUrl]];
Run Code Online (Sandbox Code Playgroud)

有没有办法在"lunchUrl"字符串的末尾添加特定日期,因此当用户打开日历时,它会显示给定的日期.

我已经尝试过以下格式:@"calshow://?= 2013 12 19",@"calshow://?= 2013-12-19",@"calshow://?= 2013 + 12 + 19" .这些似乎都不适合我...任何想法我在做错什么?

And*_*tis 27

我玩了这个url方案,并找到了这样做的方法.主要的两点是:

  1. 之后不要使用"//" calshow:
  2. 自参考日期起(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];
}
Run Code Online (Sandbox Code Playgroud)

这就是我所说的:

// 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]];
}
Run Code Online (Sandbox Code Playgroud)

也许你应该考虑到这calshow:不是一个公共网址方案,所以也许苹果会以这种方式使用它.或者也许他们不会(我没有研究过).


duh*_*koh 5

对于使用 momentjs 进行原生反应:

\n\n
const testDate = moment(\'2020\xe2\x80\x9304\xe2\x80\x9301\'),      // date is local time\n  referenceDate = moment.utc(\'2001\xe2\x80\x9301-01\'), // reference date is utc\n  seconds = testDate.unix() \xe2\x80\x94 referenceDate.unix();\nLinking.openURL(\'calshow:\' + seconds); //opens cal to April 1 2020\n
Run Code Online (Sandbox Code Playgroud)\n\n

https://medium.com/@duhseekoh/need-to-open-the-os-calendar-at-a-specific-date-in-react-native-55f3a085cf8e

\n