0

我正在尝试在 xcode 中构建,但我一直遇到这个问题

No visible @interface for 'NSData' declares the selector 'initWithBase64Encoding:' 

No visible @interface for 'NSData' declares the selector 'base64Encoding'

我到处都没有看过,但我的问题没有明确的解决方案。这些是给我的问题:

- (NSString*)stringFromImage:(UIImage*)image 
  {
      if(image) 
      {
          UIImage* convertImage = [GameUtility imageWithImage:image scaledToSize:CGSizeMake(80, 80)];
          NSData *dataObj = UIImageJPEGRepresentation(convertImage, 30);
          return [dataObj base64Encoding];
      }
      return @"";
  }

- (UIImage*)imageFromString:(NSString*)imageString 
  {
       NSData* imageData =[[NSData alloc] initWithBase64Encoding:imageString];
       return [UIImage imageWithData:imageData];
  }
4

3 回答 3

1

If you are targeting OS X 10.9 or iOS 7 you can use the base64EncodedStringWithOptions: method to encode the string, and the initWithBase64EncodedString:options: method to decode the string.

If you are targeting platforms earlier than this, you need to either write these methods yourself or find a library that implements them for you (as category methods of NSData). Different libraries will have different names for these methods, so make sure you check with that library's documentation or check the header.

于 2013-10-23T10:36:34.150 回答
1

使用这个 base64 文件进行编码和解码

- (NSString*)stringFromImage:(UIImage*)image 
   { 
      if(image) 
      { 
          UIImage* convertImage = [GameUtility imageWithImage:image scaledToSize:CGSizeMake(80, 80)]; 
          NSData *dataObj = UIImageJPEGRepresentation(convertImage, 30); 
          return [dataObj base64EncodedString]; 
       } 
      return @""; 
   } 

 - (UIImage *)imageFromString:(NSString*)imageString 
   { 
      NSData* imageData =[imageString base64DecodedData]; 
      return [UIImage imageWithData:imageData]; 
   } 
于 2013-10-23T10:32:20.247 回答
1

您可以先将图像转换为这样的字符串。然后您可以尝试将您的数据转换UIImageNSData& 然后使用encodeBase64WithData

NSString * Image = [self encodeBase64WithData:[imageDict objectForKey:@"Image"]];

然后尝试UIImage像这样串起来

[UIImage imageWithData: [self decodeBase64WithString:[registerDataDict objectForKey:@"Image"]]];

希望对你有帮助

于 2013-10-23T10:36:00.943 回答