How do you detect when a file is changed in iCloud?

耗尽温柔 提交于 2019-12-04 08:56:03

The name of the NSNotification I have to listen for is NSMetadataQueryDidUpdateNotification. This is how I did it:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(queryDidUpdate:) name:NSMetadataQueryDidUpdateNotification object:query];

...

-(void)queryDidUpdate:(NSNotification *)notification {

    //something changed, reload (NSMetadataQuery, create NSPredicate, rerun the query, etc.)

}

This section of the Apple developer website contains a great tutorial for setting up document-based iCloud apps.

To answer your questions, though: as long as your document is a UIDocument you can register for a notification. Just search that page for "Monitoring Document-State Changes and Handling Errors" - there is tons of source code to help you out.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!