问题
I have just added one event on iphone calendar from below code:
EKEventStore *store=[[EKEventStore alloc] init];
[store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (!granted) {
return ;
}
EKEvent *event=[EKEvent eventWithEventStore:store];
event.title=@"This is the event";
event.startDate=[NSDate date];
event.endDate =[event.startDate dateByAddingTimeInterval:60*60];
event.allDay=YES;
NSURL *url=[NSURL URLWithString:@"http://www.google.com"];
event.URL=url;
[event setCalendar:[store defaultCalendarForNewEvents]];
NSError *errr=nil;
[store saveEvent:event span:EKSpanThisEvent commit:YES error:&errr]; // NSLog(@"%@",errr); // NSLog(@"%@",event.eventIdentifier);
}];
My event is added to default calendar:
When you click on event then you will be display this:
now i want to launch my application from one of the above screen.
回答1:
To register an own URL scheme, Apple provides a good documentation: https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AdvancedAppTricks/AdvancedAppTricks.html#//apple_ref/doc/uid/TP40007072-CH7-SW50
To do so, go to your xcode-Project file and select the build target. Head to "Info". On the bottom there is a dropdown for "URL Types". The Identifier could match the one, you got for your bundle identifier. The scheme itself is quite important, here you enter the one, you will later use. For example: "myCustomScheme"
Now bring the app on the device and provide links as followed: myCustomScheme://additionalURLWithcustomInformation/?andParametersYouWantToUseLater=1234
In the AppDelegate now implement the following method and handle the events:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
if ([[url scheme] isEqualToString:@"myCustomScheme"])
{
// Custom URL handling, for example for url parameters
}
return YES;
}
来源:https://stackoverflow.com/questions/22930281/launch-my-application-from-default-calendar