Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6474075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:32:37+00:00 2026-05-25T06:32:37+00:00

I have an object that I want to send to another device via bluetooth.

  • 0

I have an object that I want to send to another device via bluetooth. I have successfully setup the bluetooth connection and transferred an encoded NSString; however, I haven’t figured out how to use the archiving and encoding tools correctly to send an Object.

I want to send the object defined below called ChatMessage. It implements the NSCoding delegate methods initWithCoder and encodeWithCoder as seen below.

In the second code snippet, I have the code for sending and receiving the data i.e. the methods that result in the de-encoder being called.

It keeps crashing on the last line of the decode method. I’ve been struggling to figure it out what is going wrong. Any help would be greatly appreciated!

@interface ChatMessage : NSObject <NSCoding> {
    NSString *sender;
    NSString *message; 
}

@property (nonatomic, retain) NSString *sender;
@property (nonatomic, retain) NSString *message;

@end

- (void)encodeWithCoder:(NSCoder *)coder {
    [coder encodeObject:sender forKey:@"sender"];
    [coder encodeObject:message forKey:@"message"];
}

- (id)initWithCoder:(NSCoder *)coder {
    sender = [[coder decodeObjectForKey:@"sender"] retain];
    message = [[coder decodeObjectForKey:@"message"] retain];
    return self;
}

In my View, the protocol for the PeerPicker Delegate functions.

- (void) receiveData:(NSData *)data 
        fromPeer:(NSString *)peer 
       inSession:(GKSession *)session 
         context:(void *)context {  

ChatMessage *aMsg = [[ChatMessage alloc] init];

NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc]
                                      initForReadingWithData:data];
@try {
    aMsg = [unarchiver decodeObjectForKey:@"myMessage"];
}
@catch (NSException *exception) {
    NSLog(@"Error: %@", exception);
}
@finally {
}

if (!messages) messages = [[NSMutableArray alloc] init];
    [messages addObject:aMsg];

// reload the table
[messageList reloadData];

[unarchiver finishDecoding];
[unarchiver release];
[data release];


}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:32:38+00:00Added an answer on May 25, 2026 at 6:32 am

    — The code was crashing because I had

    [data release];

    I found this using the instruments tool.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object of type Hash that I want to loop over via
I have a traceback object that I want to show in the nice format
I have one very general object that I want to map to a destination
I have a custom principal object that I want to be able to serialize
I have an object that implements an interface. I want to call on the
I want to have a generic object that implements an interface. I mean if
I have a flash object in my page that i want to make as
I want a Python object that will monitor whether other objects have changed since
My requirement is that I want an object (tee) to update if there have
I have an ORM mapped object, that I want to update. I have all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.