0

I am tring to create an image using the NSData collected from Bluetooth. The data is saved in NSData variable recdata which is then converted to image using imageWithData. I am trying to save this image to the Photo library using the code below. But I don't see the image in the photo library. Am I missing something??

Also, as I am doing this project where I am receiving the data from bluetooth, I don't know how to check the error message on my iPhone screen. Currently, I am using the [information setText:[NSString stringWithFormat:@"%@", error.localizedFailureReason ]]; from the completionhandler to print the error message. But nothing gets printed and the app crashes and closes down.

            [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
                //PHAssetResourceType assetType = PHAssetResourceTypePhoto;
                UIImage *image = [UIImage imageWithData:recdata];

                [PHAssetChangeRequest creationRequestForAssetFromImage: image];

                [information setText:[NSString stringWithFormat:@"Krishna"]];
                //PHAssetCreationRequest *request = [PHAssetCreationRequest creationRequestForAssetFromImage: image];
                //PHAssetResourceCreationOptions *creationOptions = nil;
                //creationOptions.originalFilename = command1; // Name of the file to be taken from command1
                //[request addResourceWithType:assetType data:rxdata options:creationOptions];  //rxdata has all the data needed for the file to be transferred to the final image file.
            } completionHandler:^(BOOL success, NSError *error) {
                [information setText:[NSString stringWithFormat:@"%@", error.localizedFailureReason ]];
            }]; 
bob
  • 33
  • 5
  • You need to provide details about the crash. What line exactly causes the crash? What is crash error message? – rmaddy Oct 01 '16 at 22:05
  • I worked on it. It does not crash but I get this error. It says Error Domain - NSCocoaErrorDomain Code = -1 "null"... – bob Oct 02 '16 at 02:10
  • Is `image` nil? – Larme Oct 02 '16 at 16:47
  • It is not nil. There is no image created. The completion handler gives me an error saying "Error Domain=NSCocoaErrorDomain Code=-1"(null)"" – bob Oct 06 '16 at 02:59

0 Answers0