Ios 当应用程序在后台运行时,如何使用AlasSetLibraryChangedNotification检测照片资源中的更改
我使用AlasSetLibraryChangedNotification检测照片资产中的更改。 它可以正常工作,但问题是我每次都需要打开应用程序来检测变化。我怎样才能在后台做到这一点? 这是我的密码Ios 当应用程序在后台运行时,如何使用AlasSetLibraryChangedNotification检测照片资源中的更改,ios,swift,nsnotificationcenter,alassetslibrary,Ios,Swift,Nsnotificationcenter,Alassetslibrary,我使用AlasSetLibraryChangedNotification检测照片资产中的更改。 它可以正常工作,但问题是我每次都需要打开应用程序来检测变化。我怎样才能在后台做到这一点? 这是我的密码 override func viewWillAppear(animated: Bool) { NSNotificationCenter.defaultCenter().addObserver(self, selector: "assetChange:", name: ALAssetsLibr
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
}
}
}
是否尝试将代码放入AppDelegate.m中?是的,我将代码放入AppDelegate文件中的函数func application:UIApplication,didFinishLaunchingWithOptions launchOptions:[NSObject:AnyObject]?但这不是工作