NSDictionary / Base64 String Logs

心不动则不痛 提交于 2019-12-11 06:46:15

问题


I have this weird problem about NSDictionary and base64 String and I cannot locate where the problem is.
Here's the code:

  NSData *pictureData = [[NSData alloc]init];
    pictureData = UIImagePNGRepresentation([UIImage imageNamed:@"logo"]);
    NSString * picture = [pictureData base64EncodedString];
    picture = [picture stringByReplacingOccurrencesOfString:@"+" withString:@"%2B"];
    if(picture == nil){
        picture = @"";
    }

self.postDictionary = [[NSDictionary alloc]initWithObjectsAndKeys:picture,@"picture",@"some text",@"caption", nil];

What happens is If I log the string,"picture", the log is very fine and okay. But when I try logging the dictionary it says something like this

{
caption = "some text";
picture = "iVBORw0KGgoAAAANSUhEUgAAAoAAAABYCAIAAADqXdEfAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAHGlET1QAAAACAAAAAAAAACwAAAAoAAAALAAAACwAAI2cl9ZnZQAAQABJREFUeAGM3euyXVl5HmDdWa7EuYec7sDBlZSrErtS+RP/clXiuCr+YzAYaKDpBmPABpr0S...and it gets CUT some part then... picture = iVBORw0KGgoAAAANSUhEUgAAAoAAAABYCAIAAADqXdEfAAAACXBIWXMAABYlAAAWJQFJUiTwAAAAHGlET1QAAAACAAAAAAAAACwAAAAoAAA..till the end of the base64 string";
}

The problem is the word "picture" as key is found also in the string object inside picture. The base64 string was cut first then followed by the picture = then the full text of the base64 string

Does not happen on simulator but happens on device. Before was just fine. I didn't changed anything on the codes. and I cannot change the NSDictionary codes also.

If I don't log it it's still like that when the web service receives the POST.

So if you guys can help me find a way. Thanks :)

来源:https://stackoverflow.com/questions/17985121/nsdictionary-base64-string-logs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!