通过iphone上的应用程序创建日历(在ios本机日历中)
我想知道是否可以通过应用程序为iphone创建新日历。我知道你可以用一个应用程序设置事件,但我可以通过应用程序制作另一个日历来放置所有事件吗 编辑: 如果不可能,最好的解决方法是什么,制作日历和事件存储,并使用nscoding保存这些信息?然后再取回 如果有可能创建一个新日历以与现有日历集成,这就是我想要做的。看看,似乎不可能通过编程方式创建新日历。但是,您可以获得现有日历的列表并找到默认日历 希望这能有所帮助。看看,似乎不可能通过编程方式创建新日历。但是,您可以获得现有日历的列表并找到默认日历通过iphone上的应用程序创建日历(在ios本机日历中),ios,objective-c,iphone,Ios,Objective C,Iphone,我想知道是否可以通过应用程序为iphone创建新日历。我知道你可以用一个应用程序设置事件,但我可以通过应用程序制作另一个日历来放置所有事件吗 编辑: 如果不可能,最好的解决方法是什么,制作日历和事件存储,并使用nscoding保存这些信息?然后再取回 如果有可能创建一个新日历以与现有日历集成,这就是我想要做的。看看,似乎不可能通过编程方式创建新日历。但是,您可以获得现有日历的列表并找到默认日历 希望这能有所帮助。看看,似乎不可能通过编程方式创建新日历。但是,您可以获得现有日历的列表并找到默认日历
希望这能有所帮助。我就是这样做的:
-(NSString*)createCal:(NSString*)myCalId;{
// Instantiate eventstore object
EKEventStore *store = [[EKEventStore alloc] init];
EKSource *localSource = nil;
for (EKSource *source in store.sources)
if (source.sourceType == EKSourceTypeLocal){
localSource = source;
break;
}
//this is you creating your calendar
EKCalendar *cal;
cal = [EKCalendar calendarWithEventStore:store];
cal.title = @"Name of calendar";
cal.source = localSource;
[store saveCalendar:cal commit:YES error:nil];
NSLog(@"cal id = %@", cal.calendarIdentifier);
return cal.calendarIdentifier;}
您需要导入
这是非常强大的,因此您需要小心并进行大量验证,例如,如果日历已经存在,等等。希望这能有所帮助。我就是这样做的:
-(NSString*)createCal:(NSString*)myCalId;{
// Instantiate eventstore object
EKEventStore *store = [[EKEventStore alloc] init];
EKSource *localSource = nil;
for (EKSource *source in store.sources)
if (source.sourceType == EKSourceTypeLocal){
localSource = source;
break;
}
//this is you creating your calendar
EKCalendar *cal;
cal = [EKCalendar calendarWithEventStore:store];
cal.title = @"Name of calendar";
cal.source = localSource;
[store saveCalendar:cal commit:YES error:nil];
NSLog(@"cal id = %@", cal.calendarIdentifier);
return cal.calendarIdentifier;}
您需要导入
这是非常强大的,因此您需要小心并进行大量验证,例如,如果日历已经存在,等等。希望这有帮助。您不能再使用标准的init方法了;它已被弃用。此处引用EKEventStore类参考: 在iOS 5及更高版本上,使用默认的init方法初始化事件存储对象。在iOS 6及更高版本上,在使用requestAccessToEntityType:completion:初始化事件存储后,必须请求访问实体类型,才能返回数据 在OS X上,使用initWithAccessToEntityTypes:而不是默认的init方法。可接受的实体类型为事件的eEntityMaskeEvent和提醒的eEntityMaskreMinder。“ 因此,如果使用iOS6,它类似于: 及 我的MacOSX应用程序需要它。所以我必须用这个: 所以在我的例子(MacOSX)中,就是这个解决方案。这是Sparqs代码;只需使用新的init而不是标准的init进行修改:
你不能再使用标准的init方法了;它已被弃用。此处引用EKEventStore类参考: 在iOS 5及更高版本上,使用默认的init方法初始化事件存储对象。在iOS 6及更高版本上,在使用requestAccessToEntityType:completion:初始化事件存储后,必须请求访问实体类型,才能返回数据 在OS X上,使用initWithAccessToEntityTypes:而不是默认的init方法。可接受的实体类型为事件的eEntityMaskeEvent和提醒的eEntityMaskreMinder。“ 因此,如果使用iOS6,它类似于: 及 我的MacOSX应用程序需要它。所以我必须用这个: 所以在我的例子(MacOSX)中,就是这个解决方案。这是Sparqs代码;只需使用新的init而不是标准的init进行修改:
我将myCalid添加为参数,因为有时您可能希望向其发送cal id以确保日历尚未创建。我将myCalid添加为参数,因为有时您可能希望向其发送cal id以确保日历尚未创建。
cal = [EKCalendar calendarForEntityType:EKEntityTypeEvent eventStore:store];
-(NSString*)createCal:(NSString*)myCalId;{
// Instantiate eventstore object
EKEventStore *store = [[EKEventStore alloc] initWithAccessToEntityTypes:EKEntityMaskEvent];
EKSource *localSource = nil;
for (EKSource *source in store.sources)
if (source.sourceType == EKSourceTypeLocal){
localSource = source;
break;
}
//this is you creating your calendar
EKCalendar *cal;
cal = [EKCalendar calendarForEntityType:EKEntityTypeEvent eventStore:store];
cal.title = @"Name of calendar";
cal.source = localSource;
[store saveCalendar:cal commit:YES error:nil];
NSLog(@"cal id = %@", cal.calendarIdentifier);
return cal.calendarIdentifier;}