requestAccessToEntity iOS6-向后兼容性 - EKEventStore [英] requestAccessToEntity iOS6- Backwards compatibility - EKEventStore

查看:89
本文介绍了requestAccessToEntity iOS6-向后兼容性 - EKEventStore的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关注iOS6 eventKit和新的隐私设置我正在使用以下代码 - 这在iOS6设备上完全正常。

following iOS6 eventKit and the new privacy settings I am using the following code - which works perfectly fine on iOS6 devices.

仍然,我想要相同的代码也适用于iOS 5.x的设备,我希望不要两次写相同的代码 - 似乎错了。

Still, I would like the same code to work also for devices with iOS 5.x and I wish not to write a the "same code" twice - Seems wrong.

任何人都可以协助优雅解决方案

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

我认为应该减少代码重复。

I think that should reduce code duplication.

这篇关于requestAccessToEntity iOS6-向后兼容性 - EKEventStore的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆