Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 当应用程序在后台运行时,如何使用AlasSetLibraryChangedNotification检测照片资源中的更改_Ios_Swift_Nsnotificationcenter_Alassetslibrary - Fatal编程技术网

Ios 当应用程序在后台运行时,如何使用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

我使用AlasSetLibraryChangedNotification检测照片资产中的更改。 它可以正常工作,但问题是我每次都需要打开应用程序来检测变化。我怎样才能在后台做到这一点? 这是我的密码

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]?但这不是工作