2014-02-08 2 views
1

대부분의 방법은 UIImageWriteToSavedPhotosAlbum()을 가리키고 있지만 iOS 6 이상에서는 카메라 롤에 쓸 사용자 권한이 필요하므로 "아니오"라고 대답하면 코드를 호출 할 수 있기를 원합니다.iOS 6/7의 카메라 롤/사진 앨범에 어떻게 이미지를 저장하나요?

"실패"에 대한 코드를 호출 할 수있는 블록 기반 방법이 있습니까?

+1

이 함수의 세번째 파라미터가 실패한다면 호출 될 completionSelector이다. – KudoCC

답변

8

확인이

/* Save to the photo album */ 
UIImageWriteToSavedPhotosAlbum(imageToSave , 
           self, // send the message to 'self' when calling the callback 
           @selector(thisImage:hasBeenSavedInPhotoAlbumWithError:usingContextInfo:), // the selector to tell the method to call on completion 
           NULL); // you generally won't need a contextInfo here); 

- (void)thisImage:(UIImage *)image hasBeenSavedInPhotoAlbumWithError:(NSError *)error usingContextInfo:(void*)ctxInfo { 
if (error) { 
    // Do anything needed to handle the error or display it to the user 
} else { 
    // .... do anything you want here to handle 
    // .... when the image has been saved in the photo album 
} 
} 
관련 문제