我的应用程序使用“ALAssetsGroup”来跟踪用户相册
然后我在我的应用程序中显示这些相册 用户可以单击相册并查看图像。
现在,当用户通过 safari 下载图像或他以任何方式更改相册时,问题就出现了。
我的应用程序仍然引用旧专辑而不是新专辑 所以我尝试使用
- (void)applicationWillEnterForeground:(UIApplication *)application
但专辑似乎还是旧的值(value), 如果我在应用程序“内部”再次刷新它们,它们将获得正确的值。
还有什么我可以用来解决这个问题的东西吗? 也许是一个通知..?
最佳答案
//This Registers a Notification for any changes
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didChangeLibrary:)
name:ALAssetsLibraryChangedNotification
object:[AGImagePickerController defaultAssetsLibrary]];
- (void)didChangeLibrary:(NSNotification *)notification
{
//Enter some code here to deal with the album changing
}
编辑:这似乎在 iOS 5 上不起作用(已为 Apple 打开雷达,因为这是一个错误)。
这是一个可以同时使用的解决方法:
Call
[self.assetsLibrary writeImageToSavedPhotosAlbum:nil metadata:nil
completionBlock:^(NSURL *assetURL, NSError *error) { }];
immediately after creating instance of ALAssetsLibrary Observe ALAssetsLibraryChangedNotification (not NSManagedObjectContextObjectsDidChangeNotification)
关于iphone - 应用程序进入前台时刷新值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10102023/