- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 ics(日历)文件,我使用 presentOptionsMenuFromRect:
使用 UIDocumentInteractionController
打开它。运行时,“打开方式”菜单看起来像 this .
如您所见,没有“添加到日历”选项。这让我明白了:我对 .vcf(名片)文件使用了完全相同的代码,它 works as expected “在联系人中打开”选项可用。
我是否在我的 Info.plist
中缺少某种访问日历的权限?为什么 UIDocumentInteractionController
不能正确处理 .ics
文件类型,而 .vcf
却能正常工作?这两种文件类型非常相似。从选项菜单中,如果我将 ics 文件邮寄给自己并从邮件应用程序打开它,它会很好地读取它,并且我可以将事件添加到我的日历中,所以我知道数据是有效的。我四处寻找解决方案,似乎没有人知道为什么日历访问不起作用。我遇到的一些问题仍未得到解答:
Unable to Add ics file to Calendar
How can I have UIDocumentInteractionController show Calendar as an option for opening a .ics file?
如果 Apple 是故意这样做的,我能想到的唯一原因是因为他们宁愿开发人员使用 EventKit 将事件添加到 Calendar。如果为真,则该解决方案相当令人沮丧。对此问题的任何见解将不胜感激。
最佳答案
我最终通过 ( https://github.com/KiranPanesar/MXLCalendarManager) 下载了 .ics 文件。然后我能够使用 EventKit 将下载的 .ics 文件解析为 EKEvent 并通过 EKEventEditViewController ( https://developer.apple.com/library/prerelease/ios/samplecode/SimpleEKDemo/Listings/Classes_RootViewController_m.html ) 打开它。稍微转了一圈,但似乎奏效了。以下是我如何设置实现此功能的 webview Controller 类:
@interface WebViewController : UIViewController <UIWebViewDelegate, EKEventEditViewDelegate> {
// EKEventStore instance associated with the current Calendar application
@property (nonatomic, strong) EKEventStore *eventStore;
// Default calendar associated with the above event store
@property (nonatomic, strong) EKCalendar *defaultCalendar;
@end
@implementation WebViewController
- (void)viewDidLoad {
[super viewDidLoad];
...
// Initialize the event store
self.eventStore = [[EKEventStore alloc] init];
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSURL *url = [request URL];
NSString *path = [url absoluteString];
NSRange range = [path rangeOfString:@".ics" options:NSCaseInsensitiveSearch];
if (range.length > 0) {
[self checkCalendarAndAddEvent:url];
return NO;
}
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
return YES;
}
-(void)checkCalendarAndAddEvent:(NSURL*)url
{
EKAuthorizationStatus status = [EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent];
if(status == EKAuthorizationStatusAuthorized)
{
[self addEventToCalendar:url];
} else
{
[self.eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)
{
if (granted)
{
// Let's ensure that our code will be executed from the main queue
dispatch_async(dispatch_get_main_queue(), ^{
// The user has granted access to their Calendar; add to calendar
[self addEventToCalendar:url];
});
}else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Privacy Warning" message:@"Permission was not granted for Calendar"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
}];
}
}
-(void) addEventToCalendar: (NSURL *)url
{
MXLCalendarManager* calendarManager = [[MXLCalendarManager alloc] init];
self.defaultCalendar = self.eventStore.defaultCalendarForNewEvents;
[calendarManager scanICSFileAtRemoteURL:url withCompletionHandler:^(MXLCalendar *calendar, NSError *error) {
MXLCalendarEvent *mxlEvent = calendar.events.firstObject;
EKEventEditViewController *addController = [[EKEventEditViewController alloc] init];
EKEvent * event = [EKEvent eventWithEventStore:self.eventStore];
event.location = mxlEvent.eventLocation;
event.startDate = mxlEvent.eventStartDate;
event.endDate = mxlEvent.eventEndDate;
event.title = mxlEvent.eventSummary;
event.notes = mxlEvent.eventDescription;
addController.event = event;
// Set addController's event store to the current event store
addController.eventStore = self.eventStore;
addController.editViewDelegate = self;
[self presentViewController:addController animated:YES completion:nil];
}];
}
@end
我还必须稍微修改 MXLCalendarManager.m 的部分内容,以便为我的特定类型的 .ics 格式设置做好准备。例如,我的 .ics 文件的摘要部分如下所示:
DESCRIPTION;LANGUAGE=en-us:The following details your appointment:\n\n\n
MXLCalendarManager 只在寻找:
DESCRIPTION: (Something).
我修改了代码以说明 ;ln。这也删除了所有人为的换行符,但允许我在摘要描述中添加我自己的换行符:
// Extract event description
[eventScanner scanUpToString:@"DESCRIPTION" intoString:nil];
[eventScanner scanUpToString:@":" intoString:nil];
[eventScanner scanUpToString:@"\nSEQUENCE" intoString:&descriptionString];
if(descriptionString.length > 1)
{
descriptionString = [descriptionString substringFromIndex:1];
descriptionString = [[[descriptionString stringByReplacingOccurrencesOfString:@"\nSEQUENCE" withString:@""] stringByReplacingOccurrencesOfString:@"\r\n " withString:@""] stringByReplacingOccurrencesOfString:@"\\n" withString:@"\n"];
}
关于ios - UIDocumentInteractionController 日历访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27927665/
是否可以检查设备上有多少个能够处理特定文件类型的应用程序?基本上,我的应用程序中有一个按钮,允许用户在另一个应用程序中打开,但如果没有可能的应用程序可以打开文档,我不想显示它。 最佳答案 好吧,所以想
我不知道这段代码有什么问题,但每次运行应用程序时,显示菜单后,应用程序都会崩溃。 NSString * path = [[NSBundle mainBundle] pathForResource:@"
我在容器 View 中有一个 UIViewController。 View Controller 在 UIDocumentInteractionController 中显示 PDF,如下所示: let
我有一个 PDF 显示在 UIDocumentInteractionController它很棒。 问题是,该应用程序的重点是保护 PDF 不被共享等。因此我想摆脱出现的选项按钮。 堆栈上有 1000
我一直在使用 Apple 示例代码从这里查看文档: https://developer.apple.com/library/ios/samplecode/DocInteraction/Listings
我有从 UIAlertController 中调用的代码: func createSomeFile() { var output = (some NSData to output to fil
如何指定可用于 UIDocumentInteractionController 的“打开方式”功能的特定“白”应用程序列表?我在 UIDocumentInteractionController 文档中
我的应用程序中的一个屏幕显示了本地镜像的预览,我在左上角有一个操作按钮,我用它来显示文档交互选项: - (IBAction)actionButtonTapped:(id)sender { se
我有一个 ics(日历)文件,我使用 presentOptionsMenuFromRect: 使用 UIDocumentInteractionController 打开它。运行时,“打开方式”菜单看起
我的 IOS 应用程序的方向已锁定为纵向模式。但是,我想支持使用 UIDocumentInteractionController 打开的文件的横向和纵向。这是我打开文件 url 的代码。 let u
我使用 UIDocumentInteractionController 在我的应用程序中预览文档。但是,有时文档显示良好,有时交互 Controller 显示消息“读取文档时出错”。我知道这不是文档的
我对 UIDocumentInteractionController 非常绝望。我唯一想做的就是与注册 PDF 的所有其他应用程序共享我的应用程序中的 pdf 文件。 这是我的代码: NSString
这里有一个奇怪的 iOS 问题... 我有一个可以在我的 iPad 上打开 PDF 的应用程序。 (我只需要在我所处的环境中处理 iPad) 奇怪的是,有时当我尝试加载文件时(DocumentInte
我使用- (BOOL)presentPreviewAnimated:(BOOL)animated; 来加载文档,然后我想从文档中截取屏幕截图。所以我尝试 UIGraphicsBeginImageCon
在我的应用程序中,我下载各种格式的文件。我试图让 UIDocumentInteractionController 获得可以打开这种格式的应用程序。问题是 UIDocumentInteractionCo
我想在应用程序中分享保存的 PDF。实际上,它不适用于 PRINT,也不适用于 MAIL,它正在通过 Whatsapp 和其他应用程序进行共享。 { let fileManager = Fil
在我的 iOS 应用程序中,我使用 DocumentInteractionController 来预览 .csv 文档。 self.documentController = [UIDocume
在我的应用程序中,我想下载各种类型的文件并导出,以便用户可以使用打开此类文件的应用程序打开文件。我正在尝试使用 UIDocumentInteractionController 但在下载后将其保存到我的
我正在使用 UIDocumentInteractionController 与其他应用程序共享在我的应用程序中拍摄的图像。当您使用它与 Instagram 分享时,您可以使用包含键 @"Instagr
当用户从 tableView 中选择一个文件时,我试图从导航 Controller 中呈现一个 UIDocumentInteractionController。 interactionControll
我是一名优秀的程序员,十分优秀!