2014-11-24 66 views
0

我想從新應用程序中保存所有圖像(使用我的應用程序名稱)。所以我在我的項目中使用了斷言庫。它在ios 7中運行良好,但在ios8和後續版本中運行良好。當用戶從照片中刪除相冊時,出現錯誤,斷言庫無法在ios8中重新創建具有相同名稱的新相冊。任何人都有這個解決方案?由於AssetsLibrary框架無法在iOS 8中刪除相冊後工作

+0

通過這個link.it可以幫助you.http創建相冊://stackoverflow.com/questions/26003211/assetslibrary- framework-broken-on-ios-8 – BHUMICA 2014-11-24 05:27:54

+0

是的,它正在工作,但我無法理解完整的代碼。所以當我試圖保存照片時,它又創建了一張新專輯,那麼你能給我一個標準代碼嗎?請保留相冊名稱爲照片應用 並感謝您重播我 – user3418619 2014-11-25 09:45:21

回答

-1

你可以試試下面我爲法適用於iOS 7和iOS 8

#define PHOTO_ALBUM_NAME @"AlbumName Videos" 

#pragma mark - Create Album 
-(void)createAlbum{ 

// PHPhotoLibrary_class will only be non-nil on iOS 8.x.x 
Class PHPhotoLibrary_class = NSClassFromString(@"PHPhotoLibrary"); 

if (PHPhotoLibrary_class) { 


    // iOS 8..x. . code that has to be called dynamically at runtime and will not link on iOS 7.x.x ... 

    [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{ 
     [PHAssetCollectionChangeRequest creationRequestForAssetCollectionWithTitle:PHOTO_ALBUM_NAME]; 
    } completionHandler:^(BOOL success, NSError *error) { 
     if (!success) { 
      NSLog(@"Error creating album: %@", error); 
     }else{ 
      NSLog(@"Created"); 
     } 
    }]; 
}else{ 
    [self.library addAssetsGroupAlbumWithName:PHOTO_ALBUM_NAME resultBlock:^(ALAssetsGroup *group) { 
     NSLog(@"adding album:'Compressed Videos', success: %s", group.editable ? "YES" : "NO"); 

     if (group.editable == NO) { 
     } 

    } failureBlock:^(NSError *error) { 
     NSLog(@"error adding album"); 
    }]; 
}}