I played with this url scheme a little and found the way to do it. The main two points are:
- Don't use "//" after the
calshow:
- Pass timestamp since reference date (1 Jan 2001)
Here is the code:
- (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];
}
And this is how I call it:
// 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]];
}
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).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…