需要在Xcode工程目录Classes-->Unity文件下面添加两个文件PhotoManager.h和PhotoManager.m
PhotoManager.h代码如下
#import <Foundation/Foundation.h>
@interface PhotoManager : NSObject
- ( void ) imageSaved: ( UIImage *) image didFinishSavingWithError:( NSError *)error
contextInfo: ( void *) contextInfo;
@end
PhotoManager.m代码如下
#import "PhotoManager.h"
@implementation PhotoManager
- ( void ) imageSaved: ( UIImage *) image didFinishSavingWithError:( NSError *)error
contextInfo: ( void *) contextInfo
{
NSLog(@"保存结束");
if (error != nil) {
NSLog(@"有错误");
}
}
void _SavePhoto(char *readAddr)
{
NSString *strReadAddr = [NSString stringWithUTF8String:readAddr];
UIImage *img = [UIImage imageWithContentsOfFile:strReadAddr];
NSLog([NSString stringWithFormat:@"w:%f, h:%f", img.size.width, img.size.height]);
PhotoManager *instance = [PhotoManager alloc];
UIImageWriteToSavedPhotosAlbum(img, instance,
@selector(imageSaved:didFinishSavingWithError:contextInfo:), nil);
}
@end