ios - nsstring causing my app to crash -
i created dictionary hold post params.
nsdictionary *post_params = [nsdictionary dictionarywithobjectsandkeys: [[asidentifiermanager sharedmanager].advertisingidentifier uuidstring], @"advertisingid", [[nsbundle mainbundle] objectforinfodictionarykey: @"cfbundleshortversionstring"], @"appversion", [[uidevice currentdevice]systemversion], @"devicesystemversion", [[nsuserdefaults standarduserdefaults] objectforkey:@"apnstoken"], @"apnstoken", [[nsuserdefaults standarduserdefaults] objectforkey:@"userid"], @"userid",nil];
the above post params appended post request code :
for (id key in params) { [body appenddata:[[nsstring stringwithstring:[params objectforkey:key]] datausingencoding:nsutf8stringencoding]]; }
the above code executed within send_post_request
function.
i received crash report
0 corefoundation 0x182a982d8 __exceptionpreprocess + 132 (nsexception.m:162) 1 libobjc.a.dylib 0x1947640e4 objc_exception_throw + 60 (objc-exception.mm:527) 2 corefoundation 0x182a9f3a4 __methoddescriptionforselector + 0 (nsobject.m:368) 3 corefoundation 0x182a9c154 ___forwarding___ + 928 (nsforwarding.m:2878) 4 corefoundation 0x18299eccc _cf_forwarding_prep_0 + 92 (nsforwarding.s:772) 5 foundation 0x1838cc864 -[nsplaceholderstring initwithstring:] + 180 (nsstring.m:1973) 6 foundation 0x1838d2e14 +[nsstring stringwithstring:] + 56 (nsstring.m:152) 7 zvsdv 0x100084f70 +[zvsdvutableurlrequest send_post_request:params] + 800 (zvsdvutableurlrequest.m:79)
this report show app crash when executing line of code :
[body appenddata:[[nsstring stringwithstring:[params objectforkey:key]] datausingencoding:nsutf8stringencoding]];
this reason :
[params objectforkey:key]
return nil value. can't happen. becausensdictionary
can't hold nil value.[params objectforkey:key]
return integer. surensuserdefaults
returnnsstring
object. , other params objects shouldnsstring
.
what problem ?
one of objects in params
in not nsstring.
run check out
(id key in params) { if (![[params objectforkey:key] iskindofclass:[nsstring class]]) { nslog(@"the object key '%@' not string. it's %@", key, nsstringfromclass([[params objectforkey:key] class])); } }
Comments
Post a Comment