【问题标题】:Launch my application from default calendar从默认日历启动我的应用程序
【发布时间】:2014-04-08 07:24:43
【问题描述】:

我刚刚从下面的代码在 iphone 日历上添加了一个事件:

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);

    }];

我的活动已添加到默认日历:

当您单击事件时,您将显示以下内容:

现在我想从上述屏幕之一启动我的应用程序。

【问题讨论】:

  • 使用您的应用注册的方案而不是 google url 指定一个。
  • 尝试使用 url 方案,您可以使用它打开您的应用程序

标签: ios objective-c eventkit


【解决方案1】:

要注册一个自己的 URL 方案,Apple 提供了一个很好的文档: https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AdvancedAppTricks/AdvancedAppTricks.html#//apple_ref/doc/uid/TP40007072-CH7-SW50

为此,请转到您的 xcode-Project 文件并选择构建目标。 前往“信息”。在底部有一个“URL 类型”的下拉菜单。 标识符可以匹配一个,你得到你的包标识符。方案本身是相当重要的,这里你输入一个,你以后会用到。例如:“myCustomScheme”

现在将应用程序带到设备上并提供如下链接: myCustomScheme://additionalURLWithcustomInformation/?andParametersYouWantToUseLater=1234

现在在 AppDelegate 中实现以下方法并处理事件:

- (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;
}

【讨论】:

  • 你可以传递任何你想要的,但使用自定义方案。例如。而不是“google.com”使用“myCustomScheme://google.com”。如果您想从日历中打开应用程序,我希望应用程序能够处理我选择的正确事件。因此,您可以传递事件的 ID 或日期。 "myCustomScheme://08-04-2014/"
  • 谢谢@Lepidopternon 它帮助了我,现在我也想做反之亦然。表示我要启动 iPhone 的默认日历应用程序,我该怎么办?
  • 要返回,您可以使用“calshow://” - 方案,在此线程中描述:stackoverflow.com/questions/4820762/…
  • 是的,它有效。但是如果我想用特定的 EKEvent 对象打开日历,那么我应该怎么做?
  • 关于:stackoverflow.com/questions/1752342/… 只是可以创建日历事件,但不能直接在日历中打开它们。对不起。
猜你喜欢
  • 2017-11-22
  • 1970-01-01
  • 1970-01-01
  • 2017-06-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多