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 :

  1. [params objectforkey:key] return nil value. can't happen. because nsdictionary can't hold nil value.

  2. [params objectforkey:key] return integer. sure nsuserdefaults return nsstring object. , other params objects should nsstring.

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

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -