objective-c – requestAccessToEntity iOS6-向后兼容性 – EKEv
发布时间:2020-12-16 10:32:12 所属栏目:百科 来源:网络整理
导读:跟随iOS6 eventKit和新的隐私设置我使用以下代码 – 这在iOS6设备上运行得非常好. 不过,我希望相同的代码也适用于iOS 5.x的设备,我希望不要两次写“相同的代码” – 似乎错了. 任何人都可以协助优雅的解决方案? EKEventStore *eventStore = [[EKEventStore
跟随iOS6 eventKit和新的隐私设置我使用以下代码 – 这在iOS6设备上运行得非常好.
不过,我希望相同的代码也适用于iOS 5.x的设备,我希望不要两次写“相同的代码” – 似乎错了. 任何人都可以协助优雅的解决方案? EKEventStore *eventStore = [[EKEventStore alloc] init]; [eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted,NSError *error) { // some code }]; 解决方法
我正在使用这个:
void (^addEventBlock)(); addEventBlock = ^ { NSLog(@"Hi!"); }; EKEventStore *eventStore = [[UpdateManager sharedUpdateManager] eventStore]; if ([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)]) { [eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted,NSError *error) { if (granted) { addEventBlock(); } else { NSLog(@"Not granted"); } }]; } else { addEventBlock(); } 我认为这应该减少代码重复. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容