あなたの情報と画像を分離する必要があります。 アップロードしてください。
あり例:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//------------------This part is for upload------------------
//Upload info
UIImage* sourceImage = [UIImage imageNamed:@"source.png"];
UIImageView* imgV1 = [[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];
imgV1.backgroundColor = [UIColor redColor];
imgV1.image = sourceImage;
[self.view addSubview:imgV1];
NSDictionary* uploadDic = [[NSDictionary alloc] initWithObjectsAndKeys:
@"source.png",@"testImage",
nil];
NSData* uploadData = [NSJSONSerialization dataWithJSONObject:uploadDic options:NSJSONWritingPrettyPrinted error:nil];
NSString* uploadString = [[NSString alloc] initWithData:uploadData encoding:NSUTF8StringEncoding];
//Upload image
NSData* imageData = [NSData dataWithContentsOfFile:@"source.png"];
[self uploadInfoToURL:uploadString andImageData:imageData];
//-----------------------------------------------------------
//------------------This part is for upload------------------
//Download info
NSString *downLoadString = uploadString;
NSData* downLoadData = [downLoadString dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *downLoadDic = [NSJSONSerialization JSONObjectWithData:downLoadData options:NSJSONReadingMutableContainers error:nil];
UIImageView* imgV2 = [[UIImageView alloc] initWithFrame:CGRectMake(50, 250, 100, 100)];
imgV2.backgroundColor = [UIColor blueColor];
[self.view addSubview:imgV2];
//Download image
NSString* downURL = [NSString stringWithFormat:@"http://youServer/%@",[downLoadDic objectForKey:@"testImage"]];
imgV2.image = [self getImageFromURL:downURL];
//-----------------------------------------------------------
}
-(UIImage *) getImageFromURL:(NSString *)fileURL {
NSLog(@"Begin download");
UIImage * result;
NSData * data = [NSData dataWithContentsOfURL:[NSURL URLWithString:fileURL]];
result = [UIImage imageWithData:data];
return result;
}
-(BOOL *) uploadInfoToURL:(NSString *)infoString andImageData:(NSData *)data {
NSLog(@"Begin upload");
//Use http post to upload your image data to you server
// if (nil == error) {
// return YES;
// }
return NO;
}
は、それはあなたを助けることができると思います。
コードを貼り付けることはできますか? –
配列をNSDataに変換しないのはなぜですか?サーバー上に投稿し、ダウンロード後に簡単に解析できるようにデータをJSONに変換することができます。 –