遵循 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();
}
我认为这应该减少代码重复。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)