Note that there are some explanatory texts on larger screens.

plurals
  1. POGamekit and iPhone
    primarykey
    data
    text
    <p>I have my app set up to send a custom level in a form of a array to another person during a p2p connection. The receiving device saves the array to file for later use. I set up gamekit in my application, it will successfully search and connect to another device without any problems. Though a problem arises when I send data to a device, the receiving device will receive the data (and save the custom level like it should) but it will immediately crash afterwords. </p> <p>Here are my methods that I use to send and receive data. </p> <pre><code>-(void) sendDataToPeers:(NSData *) data { if (currentSession) { //send the data [self.currentSession sendDataToAllPeers:data withDataMode:GKSendDataReliable error:nil]; //Alerting the user that the custom level has been sent. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Sent!" message:@"Your custom level has been sent." delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil]; [alert show]; [alert release]; } } -(void) btnSend { //Data that will be sent NSMutableData *theData = [NSMutableData data]; //Archiver NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:theData]; //Desired level to send int theLevel =[[CTManager sharedInstance]getLevel]; //Path to the custom levels NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory=[paths objectAtIndex:0]; NSString *customLevelsSen = [documentsDirectory stringByAppendingPathComponent: [NSString stringWithFormat:@"customLevels"]]; //Custom levels array NSArray *theLevels = [[NSArray alloc] initWithContentsOfFile: customLevelsSen]; //Gets the desired level array from array of custom levels NSArray *myArray = [[NSArray alloc]initWithArray:[theLevels objectAtIndex:theLevel-51]]; //prepare data [archiver encodeObject:myArray forKey:@"level"]; [archiver finishEncoding]; //send the data [self sendDataToPeers:theData]; //cleanup [archiver release]; [theLevels release]; [myArray release]; } -(void) receiveData:(NSData *)data fromPeer:(NSString *)peer inSession:(GKSession *)session context:(void *)context { //Archiver NSKeyedUnarchiver *archiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data]; //Gets the custom level in form of an array from data. NSArray *level = [archiver decodeObjectForKey:@"level"]; [archiver finishDecoding]; [archiver release]; //Path to the array of custom levels NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory=[paths objectAtIndex:0]; NSString *customLevelsRec = [documentsDirectory stringByAppendingPathComponent: [NSString stringWithFormat:@"customLevels"]]; //Gets the array of custom levels NSMutableArray *customLevelArray = [[NSMutableArray alloc] initWithContentsOfFile:customLevelsRec]; //Adds a new array to the array of custom levels [customLevelArray addObject:level]; //Saves the array. [customLevelArray writeToFile:customLevelsRec atomically:YES]; //cleanup [customLevelArray release]; //Message saying a custom level has been recieved UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Received!" message:@"A custom level has been saved." delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil]; [alert show]; [alert release]; } </code></pre> <p>Testing this has been a pain since I don't have two devices of my own currently, so I send a beta build to my friend who inturns tests them (he has ipod and iphone). Any help with this is appreciated...</p> <p>If I can't find the problem I will most likely send the entire xcode project to him and via screen share work with the project on his computer to efficiently build and test the application. And I will be able to use debug mode. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload