I am playing with Apple sample code BTLE_TRANSFER https://developer.apple.com/library/ios/samplecode/BTLE_Transfer/Introduction/Intro.html In the sample, an iOS device "A" sends to another iOS device "B" some "text" (NSString) when B (central) subscribe to characteristic of "A" (peripheral). (The data is cut in pieces then sent by piece until everything is received on the other side)
I modified the code to transfer an image using UIImageJPEGRepresentation method and it is working fine (but takes long when size of the image is over 2 ko)
Now I would like to try to transfer an array of different objects like text, image.
I have tried the code below in the didSubscribeToCharacteristic method (Peripheral Manager side):
NSArray *MyArray;
MyArray = [[NSArray alloc]initWithObjects:@"Text1", @"Text2", nil];
_dataToSend = [NSKeyedArchiver archivedDataWithRootObject:MyArray];
where _dataToSend is the NSData that is sent
And the code below in the didUpdateValueForCharacteristic method (central side - peripheral delegate):
NSArray *My2Array = [NSKeyedUnarchiver unarchiveObjectWithData:_dataReceived];
NSLog(@"%@",[My2Array objectAtIndex:1]);
where _dataReceived is the NSData received
Each piece is received on the central side but some parts are "null" and when I try to Unarchive the data to nsarray, it says that the data is NULL.
Am I using the wrong method? Is there any other way to put an nsarray into a nsdata?
Thank you for your help
Jimmy
The code is actually working...I just retype everything from ground Sorry for bothering