我使用ALAssetsLibraryChangedNotification来检测照片资产的变化。 它会工作正常,但问题是我需要每次打开应用程序来检测更改。我怎么能在后台做到这一点? 这是我的代码
override func viewWillAppear(animated: Bool) {
NSNotificationCenter.defaultCenter().addObserver(self, selector: "assetChange:", name: ALAssetsLibraryChangedNotification, object: assetsLibrary)
}
func assetChange(notification: NSNotification) {
if var info:NSDictionary = notification.userInfo {
if((info.objectForKey(ALAssetLibraryUpdatedAssetsKey)) != nil){
var set:NSSet = info.objectForKey(ALAssetLibraryUpdatedAssetsKey) as NSSet
}
}
}