requestAccessToEntityType - 一次还是每次?

Seg*_*gev 5 cocoa-touch objective-c ios

EKEventStore *eventStore = [[UpdateManager sharedUpdateManager] eventStore];

if ([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)])
{
    [eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)
     {
         if (granted)...
Run Code Online (Sandbox Code Playgroud)

我想要求用户允许将事件添加到他的日历中.在我被授予后,我需要再次请求权限,例如我想删除一个事件(在应用程序关闭并重新打开后的另一个会话中)或者它只是一个想要的时间吗?

如果这是一次性的事情,我可以在第一次午餐时把它放在ViewDidLoad中,只是为了"摆脱它"吗?

Fab*_*ser 16

你只需要调用一次:

BOOL needsToRequestAccessToEventStore = NO; // iOS 5 behavior
EKAuthorizationStatus authorizationStatus = EKAuthorizationStatusAuthorized; // iOS 5 behavior
if ([[EKEventStore class] respondsToSelector:@selector(authorizationStatusForEntityType:)]) {
    authorizationStatus = [EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent];
    needsToRequestAccessToEventStore = (authorizationStatus == EKAuthorizationStatusNotDetermined);
}

if (needsToRequestAccessToEventStore) {
    [eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {            
        if (granted) {
            dispatch_async(dispatch_get_main_queue(), ^{
                // You can use the event store now
            });
        }
    }];
} else if (authorizationStatus == EKAuthorizationStatusAuthorized) {
    // You can use the event store now
} else {
    // Access denied
}
Run Code Online (Sandbox Code Playgroud)

但是,你不应该在第一次发布时这样做.仅在您需要时请求访问权限,直到用户决定添加事件为止.

  • `iOS模拟器中没有为访问照片,联系人,日历和提醒的应用程序显示隐私警报. - http://developer.apple.com/library/ios/#releasenotes/General/RN-iOSSDK-6_0/_index html的 (2认同)