你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> 整理UIImagePickerController、保管圖片到相冊問題

整理UIImagePickerController、保管圖片到相冊問題

編輯:IOS開發綜合

這篇文章為您講述整理UIImagePickerController、保管圖片到相冊問題的相關內容,詳細內容請看上面

//此辦法在IOS8.0零碎上,之前用代碼創立的相冊,手動刪除它,再用這個庫去創立剛被刪除的相冊,這個時分辦法回調是不會跑fail模塊的,它走的是正常流程,但是帶回來的group卻是nil形成解體緣由
ALAssetsLibrary *assetsLibrary = [[ALAssetsLibrary alloc] init];
[assetsLibrary addAssetsGroupAlbumWithName:@"IOSDevTip1" resultBlock:^(ALAssetsGroup *group12) {
    [groups addObject:group12];
} failureBlock:nil];
//為理解決IOS8.0以上零碎下無法經過代碼創立被刪除過的同名相冊
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^
 {
     [PHAssetCollectionChangeRequest creationRequestForAssetCollectionWithTitle:@"琳小兮"];
     
 } completionHandler:^(BOOL success, NSError *error)
 {
     if (!success) {
         NSLog(@"---error:%@",error.userInfo);
     }
 }];

補充

#pragma mark ----- 攝像頭和相冊相關 -----

// 判別設備能否有攝像頭
- (BOOL)isCameraAvailable {
    return [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
}

// 判別後面的攝像頭能否可用
- (BOOL)isFrontCameraAvailable {
    return [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront];
}

// 判別前面的攝像頭能否可用
- (BOOL)isRearCameraAvailable {
    return [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear];
}

// 判別能否支持某種多媒體類型:拍照片、拍視頻
- (BOOL)cameraSupportsMedia:(NSString *)paramMediaType sourceType:(UIImagePickerControllerSourceType)paramSourceType {
    __block BOOL result = NO;
    if ([paramMediaType length] == 0){
        NSLog(@"Media type is empty.");
        return NO;
    }
    NSArray *availableMediaTypes = [UIImagePickerController availableMediaTypesForSourceType:paramSourceType];
    [availableMediaTypes enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL*stop) {
        NSString *mediaType = (NSString *)obj;
        if ([mediaType isEqualToString:paramMediaType]){
            result = YES;
            *stop = YES;
        }
        
    }];
    return result;
}

// 判別攝像頭能否支持錄像
- (BOOL)doesCameraSupportShootingVideos {
    return [self cameraSupportsMedia:(NSString *)kUTTypeMovie sourceType:UIImagePickerControllerSourceTypeCamera];
}

// 判別攝像頭能否支持拍照
- (BOOL)doesCameraSupportTakingPhotos {
    return [self cameraSupportsMedia:(NSString *)kUTTypeImage sourceType:UIImagePickerControllerSourceTypeCamera];
}


#pragma mark ----- 相冊文件選取相關 -----

// 判別相冊能否可用
- (BOOL) isPhotoLibraryAvailable{
    return [UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary];
}

// 判別能否可以在相冊中選擇視頻
- (BOOL) canUserPickVideosFromPhotoLibrary {
    return [self cameraSupportsMedia:( NSString *)kUTTypeMovie sourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}

// 判別能否可以在相冊中選擇照片
- (BOOL) canUserPickPhotosFromPhotoLibrary {
    return [self cameraSupportsMedia:( NSString *)kUTTypeImage sourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}

經過本文的學習希望對您理解和學習ios開發的相關知識有一些好的協助.感激關注本站.我們將為您搜集更多更好的ios開發教程.

【整理UIImagePickerController、保管圖片到相冊問題】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved