zat*_*ata 4 iphone objective-c ios eventkit
因此,我目前正在使用 EventKit,并试图在本机日历应用程序中添加/修改/删除日历条目时触发 EKEventStoreChangedNotification,但在请求访问日历的权限后,确认我已获得授权并签名等待通知
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(storeChanged:)
name:EKEventStoreChangedNotification
object:nil];
Run Code Online (Sandbox Code Playgroud)
选择器永远不会被调用。还尝试了块语法,它也不起作用。
所以我认为我做错了什么,发现了这个示例代码,据说它有工作通知,但即使在拉出该项目并确保 addObserver 行被调用之后,我也无法看到选择器被调用当我修改日历时。
有什么想法如何进一步调试吗?
确保你的资源EKEventStore没有被释放。例如,将其分配给强属性。
当在常用日历应用程序中进行编辑时,以下应用程序会记录一个字符串:
#import <EventKit/EventKit.h>
@interface AppDelegate : UIResponder<UIApplicationDelegate>
@property (strong, nonatomic) EKEventStore *eventStore;
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.eventStore = [[EKEventStore alloc] init];
[self.eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (granted) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(eventStoreChangedNotification:) name:EKEventStoreChangedNotification object:nil];
}
}];
return YES;
}
- (void)eventStoreChangedNotification:(NSNotification *)notification {
NSLog(@"Event store changed");
}
@end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2184 次 |
| 最近记录: |