代码之家  ›  专栏  ›  技术社区  ›  Fazil

-base64编码返回类型默认为id

  •  0
  • Fazil  · 技术社区  · 12 年前

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

    密码

    [UIImageJPEGRepresentation(petAvadar.image, 1.0)base64Encoding]
    

    警告

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

    如何删除此警告,请帮助我解决。

    3 回复  |  直到 12 年前
        1
  •  2
  •   Community Mohan Dere    8 年前

    然后按照以下方式将UIImage对象转换为NSData:

    NSData *imageData = UIImageJPEGRepresentation(image, 1.0);
    

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

    NSString *encodedString = [imageData base64Encoding];
    

    once check this one

        2
  •  1
  •   rdurand    12 年前

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

    您应该添加一行,如下所示:

    -(returnType)base64Encoding;
    

    哪里 returnType 是方法返回的类型,例如 NSString* , NSInteger , void 或者不管你的方法返回什么。

        3
  •  0
  •   swiftBoy Vmanani    12 年前

    请确保您没有从 here

    然后导入 基准64.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];
    

    你可能想检查一下 this this 链接也是

    推荐文章