【问题标题】:-base64Encoding return type defaults to id-base64Encoding 返回类型默认为 id
【发布时间】:2013-04-17 19:12:47
【问题描述】:

在我的应用程序中,当我尝试使用以下编码时,我收到警告为

代码

[UIImageJPEGRepresentation(petAvadar.image, 1.0)base64Encoding]

警告

Instance method '-base64Encoding' not found (return type defaults to 'id')

如何去掉这个警告,请帮我解决。

【问题讨论】:

  • whr 是你的 base64Encoding 类..?你进口了吗?

标签: iphone ipad ios6 uiimagejpegrepresentation


【解决方案1】:

你需要在头文件中声明你的函数。

你应该像这样添加一行:

-(returnType)base64Encoding;

其中returnType 是您的方法返回的类型,例如NSString*NSIntegervoid 或您的方法返回的任何类型。

【讨论】:

    【解决方案2】:

    然后通过以下方式将您的 UIImage 对象转换为 NSData:

    NSData *imageData = UIImageJPEGRepresentation(image, 1.0);
    

    然后应用Base64编码将其转换为base64编码的字符串:

    NSString *encodedString = [imageData base64Encoding];
    

    once check this one

    【讨论】:

    • 您不应该重复其他主题的答案。标记问题。
    【解决方案3】:

    确保您已从 here 下载 Base64 库类

    然后导入 Base64.h 使用下面的代码片段

    用于将图像编码为 Base64

    NSData* data = UIImageJPEGRepresentation(yourImage, 1.0f);
     [Base64 initialize];
     NSString *strEncoded = [Base64 encode:data];
    

    并将 Base64 解码为图像:

    [Base64 initialize]; 
     NSData* data = [Base64 decode:strEncoded ];;
     image.image = [UIImage imageWithData:data];
    

    您也可以查看thisthis 链接

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-28
      • 2023-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多