iphone - 应用程序进入前台时刷新值

标签 iphone ios alassetslibrary

我的应用程序使用“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/

相关文章:

iphone - "Safari cannot open the page because the address is invalid"用于 Google map 链接

ios - 滑动表格单元格即可获得两个选项

ios - 强制 ipad 方向为一个 View

ios - enumerateAssetsWithOptions 返回一个 alasset nil

ios - 将 Label 放入空的垂直 StackView 中会自动缩小堆栈

ios - --resource-rules 已在 mac os x >= 10.10 中弃用

ios编程: Using threads to add multiple images to library

ios - 适用于 ios 的 Android 应用程序包(动态功能)?

ios - 找出我的异步调用何时完成

ios5 - 无法链接ALAssetsLibrary