0

我的应用程序正在使用“ALAssetsGroup”来跟踪用户相册

我在我的应用程序中显示这些相册,用户可以单击相册并查看图像。

现在,当用户通过 safari 下载图像或以任何方式更改相册时,就会出现问题。

我的应用程序仍然引用旧专辑而不是新专辑,所以我尝试使用

- (void)applicationWillEnterForeground:(UIApplication *)application

但是这些专辑似乎仍然具有旧值,如果我在应用程序中再次刷新它们,它们会得到正确的值。

还有什么我可以用来解决这个问题的..?也许是通知..?

4

2 回答 2

2
        //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 打开了一个雷达,因为这是一个错误)。

这是同时使用的解决方法:

称呼

[self.assetsLibrary writeImageToSavedPhotosAlbum:nil metadata:nil
 completionBlock:^(NSURL *assetURL, NSError *error) { }];

创建 ALAssetsLibrary 实例后立即观察 ALAssetsLibraryChangedNotification(不是 NSManagedObjectContextObjectsDidChangeNotification)

于 2012-04-11T08:02:26.360 回答
0

使用applicationDidBecomeActiveApplicationDelegate 中的方法

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    /*
     Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
     */
}
于 2012-04-11T08:49:08.373 回答