如何从Swift应用打开日历(例如,按下按钮时)?或者有没有办法在应用中的视图控制器中嵌入日历? 我想避免使用别人编写的外部日历。谢谢!从Swift应用打开日历
3
A
回答
6
您可以通过使用URL方案calshow://
打开日历应用:
UIApplication.sharedApplication().openURL(NSURL(string: "calshow://")!)
随着EventKit,你可以实现你的自我的日历。您应该从Apple网站上阅读Calendar and Reminders Programming Guide。
1
随着HoaParis的提及,您可以使用openURL
方法调用日历。
默认情况下,苹果没有嵌入式日历,但您可以查看其他日历,例如github上提供的其他日历,例如开源软件CVCalendar。所以你可以在你的项目中使用它,或者检查开发者是如何编码日历的。
2
的OpenURL弃用iOS10
从苹果公司的指导What’s New iOS中的部分上的UIKit:
新的UIApplication方法的OpenURL:选择:completionHandler :,它执行 异步并在主队列上调用指定的完成处理程序 (此方法替换openURL :)。
斯威夫特3
func open(scheme: String) {
if let url = URL(string: scheme) {
if #available(iOS 10, *) {
UIApplication.shared.open(url, options: [:],
completionHandler: {
(success) in
print("Open \(scheme): \(success)")
})
} else {
let success = UIApplication.shared.openURL(url)
print("Open \(scheme): \(success)")
}
}
}
// Typical usage
open(scheme: "calshow://")
Objective-C的
- (void)openScheme:(NSString *)scheme {
UIApplication *application = [UIApplication sharedApplication];
NSURL *URL = [NSURL URLWithString:scheme];
if ([application respondsToSelector:@selector(openURL:options:completionHandler:)]) {
[application openURL:URL options:@{}
completionHandler:^(BOOL success) {
NSLog(@"Open %@: %d",scheme,success);
}];
} else {
BOOL success = [application openURL:URL];
NSLog(@"Open %@: %d",scheme,success);
}
}
// Typical usage
[self openScheme:@"calshow://"];
注: -不要忘了在你的info.plist文件中添加隐私用法说明。如果你正在尝试打开任何系统应用程序,那么在iOS 10+中,你需要指定pri在您的info.plist文件中出现错误的使用说明,否则您的应用程序将崩溃。
相关问题
- 1. 从小工具应用打开日历
- 2. 从WP7打开日历应用
- 3. 从uibutton打开日历
- 4. 我想从android应用程序打开日历应用程序
- 5. 如何从我的应用程序中打开iPhone日历?
- 6. 从我的应用程序打开Apple日历
- 7. 从日历中打开科尔多瓦Android应用程序
- 8. 如何从我的应用程序中打开日历?
- 9. 从日历中打开Android应用程序
- 10. 如何从钛应用程序打开本机日历?
- 11. 如何从UWP应用中打开Outlook日历与URL
- 12. 保持DIV打开时,日历打开
- 13. 日历不会打开
- 14. 在Android中打开日历
- 15. 从Android的另一个应用程序打开默认日历应用程序
- 16. 如何从我的应用程序打开谷歌日历应用程序?
- 17. 用html链接打开android日历
- 18. 打印日历或从ASP.NET日记应用
- 19. URL在日历应用程序中打开的链接
- 20. 以编程方式打开iphone日历应用程序
- 21. 在Android上打开(Google)日历应用程序URL
- 22. 如何在HTML5手机中打开日历字段的日历?
- 23. 如何从黑莓旅行等日历的网址打开应用程序?
- 24. 如何从任何其他应用程序打开内置的Google日历?
- 25. 开发日历应用为iPad
- 26. 如何从jquery日历打印日期?
- 27. jquery fullcalendar打开多个日历
- 28. 以编程方式打开primeng日历
- 29. Jquery日历不打开角js
- 30. 打开日历片段上EditText
我找不到Swift的日历编程指南,只能用于Objective-C。我更喜欢Swift。 – Amy
你可以将你自己的代码翻译成swift。或者看看这个:https://gist.github.com/mchirico/d072c4e38bda61040f91#file-cal-swift –
我们可以像UIApplication.sharedApplication()一样打开默认提醒。openURL(NSURL(string:“calshow:// “)!)? –