从NSData创建图像并使用PHPhotoLibrary

时间:2016-10-01 21:58:43

标签: ios objective-c bluetooth nsdata phphotolibrary

我想使用从蓝牙收集的NSData来创建图像。数据保存在NSData变量recdata中,然后使用imageWithData将其转换为图像。我想使用下面的代码将此图像保存到照片库。但我没有看到照片库中的图像。我错过了什么吗?

另外,当我正在做这个项目,我从蓝牙接收数据时,我不知道如何检查我的iPhone屏幕上的错误消息。目前,我正在使用[information setText:[NSString stringWithFormat:@“%@”,error.localizedFailureReason]];从completionhandler打印错误消息。但没有任何东西被打印,应用程序崩溃并关闭。

            [[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 ]];
            }]; 

0 个答案:

没有答案