bluetooth lowenergy - BTLE Corebluetooth iOS Transfer an array -
i playing apple sample code btle_transfer https://developer.apple.com/library/ios/samplecode/btle_transfer/introduction/intro.html in sample, ios device "a" sends ios device "b" "text" (nsstring) when b (central) subscribe characteristic of "a" (peripheral). (the data cut in pieces sent piece until received on other side)
i modified code transfer image using uiimagejpegrepresentation method , working fine (but takes long when size of image on 2 ko)
now try transfer array of different objects text, image.
i have tried code below in didsubscribetocharacteristic method (peripheral manager side):
nsarray *myarray; myarray = [[nsarray alloc]initwithobjects:@"text1", @"text2", nil]; _datatosend = [nskeyedarchiver archiveddatawithrootobject:myarray];
where _datatosend nsdata sent
and code below in didupdatevalueforcharacteristic method (central side - peripheral delegate):
nsarray *my2array = [nskeyedunarchiver unarchiveobjectwithdata:_datareceived]; nslog(@"%@",[my2array objectatindex:1]);
where _datareceived nsdata received
each piece received on central side parts "null" , when try unarchive data nsarray, says data null.
am using wrong method? there other way put nsarray nsdata?
thank help
jimmy
the code working...i retype ground sorry bothering
Comments
Post a Comment