2012-04-11 37 views
0

我的應用程序正在使用「ALAssetsGroup」來跟蹤用戶的相冊刷新值

的,我在我的應用程序 顯示這些相冊的用戶可以在相冊點擊並查看影像。

現在問題出現在用戶通過Safari瀏覽器下載圖像或他以任何方式更改相冊時。

我的應用程序仍持有參照舊相冊,而不是新的 所以我嘗試使用

- (void)applicationWillEnterForeground:(UIApplication *)application 

刷新專輯,但專輯似乎仍然有舊的價值, 如果我刷新他們再次在應用程序中「獲得」正確的值。

有什麼別的我可以用來解決這個問題..? 也許是通知..?

回答

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(雷達已經打開了蘋果,因爲這是一個bug)。

這裏是一個變通的方法在此期間使用:

呼叫

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

創建ALAssetsLibrary的情況下觀察 ALAssetsLibraryChangedNotification(不 NSManagedObjectContextObjectsDidChangeNotification)

後立即
+0

恐怕這並不在iOS 5.0工作,看到 – 2012-04-12 06:33:12

+0

我的編輯。它應該現在與iOS 5一起工作 – shabbirv 2012-04-12 21:03:05

0

使用applicationDidBecomeActive方法在ApplicationDelegate

- (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. 
    */ 
} 
+0

仍然給出相同的結果.. – 2012-04-11 10:04:30