32

[newEventStore defaultCalendarForNewEvents]を呼び出そうとすると、次のエラーメッセージが返されます。

[707:907] defaultCalendarForNewEvents failed: Error Domain=EKCADErrorDomain Code=1013 "The operation couldn’t be completed. (EKCADErrorDomain error 1013.)"
[707:907] Error!Failed to save appointment. Description:Error Domain=EKErrorDomain Code=1 "No calendar has been set." UserInfo=0x1fc679f0 {NSLocalizedDescription=No calendar has been set.}

アプリは長時間実行されます。問題は初めて私に来ました。電話機はIOS6Beta4を実行します。モデルはiphone4です。defaultCalendarForNewEventsメソッドがいつ失敗するか知っている人はいますか?グーグルで役立つ情報が得られません。

4

8 に答える 8

55

iOS6 では、Apple は、ユーザーが各アプリの連絡先とカレンダーのアクセシビリティを制御できるようにする新しいプライバシー コントロールを導入しました。したがって、コード側では、アクセス許可を要求する方法を追加する必要があります。iOS5以前では、いつでも呼び出すことができます

EKEventStore *eventStore = [[[EKEventStore alloc] init] autorelease];
if ([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)]) {
    // iOS 6 and later
    [eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
        if (granted) {
            // code here for when the user allows your app to access the calendar
            [self performCalendarActivity:eventStore];
        } else {
            // code here for when the user does NOT allow your app to access the calendar
        }
    }];
} else {
    // code here for iOS < 6.0
    [self performCalendarActivity:eventStore];
}
于 2012-11-19T10:07:06.140 に答える
14

– requestAccessToEntityType:completion:関数を呼び出さないと、iOS アプリは iOS6 システムのカレンダーからデータを取得できません。この関数を呼び出して 、カレンダー/リマインダーにアクセスするためのアプリへのアクセスを許可するようユーザーに求めるダイアログが表示されます。コードは次のようになります。

//CalendarEventHandler.h  
@interface CalendarEventHandler : NSObject
{
EKEventStore *eventStore;
}
@property (nonatomic, strong) EKEventStore *eventStore;


//CalendarEventHandler.m 
self.eventStore =[[EKEventStore alloc] init];
if([self checkIsDeviceVersionHigherThanRequiredVersion:@"6.0"]) {
        [self.eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {

            if (granted){
                //---- codes here when user allow your app to access theirs' calendar.

            }else
            {
                //----- codes here when user NOT allow your app to access the calendar.  
            }  
        }];

    }else {
                //---- codes here for IOS < 6.0.

    }

// 以下は、現在の ios バージョンが必要なバージョンよりも高いことを確認するためのブロックです。

 - (BOOL)checkIsDeviceVersionHigherThanRequiredVersion:(NSString *)requiredVersion
 {
  NSString *currSysVer = [[UIDevice currentDevice] systemVersion];

   if ([currSysVer compare:requiredVersion options:NSNumericSearch] != NSOrderedAscending)
   {
       return YES;
   }

       return NO;
  }
于 2012-09-25T14:52:17.677 に答える
3

解決しました。iOS6の[設定]->[プライバシー]で、カレンダーへのアプリのアクセスを誤ってオフにしました

于 2012-09-17T08:18:25.850 に答える
3

私は同じ問題を抱えていましたが、最終的にその理由を見つけました。

私の場合は、リマインダーとカレンダーのイベントを追加することでしたが、1 つを使用していEKEventStoreました。結局、私はそれらを分離し、問題は消えました:

private static let calendarEventStore = EKEventStore()
private static let remindersEventStore = EKEventStore()

だから今、私はcalendarEventStoreカレンダーイベントとremindersEventStoreリマインダーに関連するすべてのものに使用しています.

——</p>

私の意見では、それは私が要求したという事実と 1 つのエンティティに関連していdefaultCalendarForNewEventsましdefaultCalendarForNewReminders()EKEventStore

これもEKEventStoreドキュメントから:

イベント ストアから取得したイベント、リマインダー、およびカレンダー オブジェクトは、他のイベント ストアでは使用できません。

于 2017-02-26T22:53:52.040 に答える
1

迅速なフォーム

(@yunasの回答に基づく)

_estore = EKEventStore()
_estore.reset()

_estore.requestAccessToEntityType(EKEntityTypeEvent) { (granted, error) in
    if granted {
        println("allowed")
        /* ... */
    } else {
        println("not allowed")
    }           
}

「アクセス」ポップアップが開きます

于 2014-09-14T10:28:07.027 に答える
0

Xamarin ユーザーの場合:

EKEventStore eventStore = new EKEventStore();
eventStore.RequestAccess(EKEntityType.Event, (bool granted, NSError e) =>
{
    if (granted)
    {
       //Your code here when user gief permissions
    }
});
于 2015-10-26T15:35:08.043 に答える
0

Simulator/Device settings/Privacy/Calendars/YourApp に移動し、ON をタップしてカレンダーへのアクセスを許可します。コードを再試行してください。動作します。

于 2013-02-05T11:26:03.380 に答える