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 6763805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:31:12+00:00 2026-05-26T14:31:12+00:00

I am using a library called libmosquitto in an iPhone app. The library is

  • 0

I am using a library called libmosquitto in an iPhone app.

The library is written in C.
It receives push notifications and therefor runs in a thread.

I want to take the data it receives, and display it in a UITableView, however ( I think) I have to write the callbacks which libmosquitto uses as C functions rather than Objective C methods, so I cannot access ‘self’ in order to do:
[self performSelectorOnMainThread:@selector(hideActivityViewer) withObject:nil waitUntilDone:NO];

Anyone have problems like this, is there another way I could update the UI?

From inside one of my Objective C methods I call this:

mosquitto_message_callback_set(mosq, my_message_callback); 

And my_message_callback is defined as:

void my_message_callback(void *obj, struct mosquitto_message *message)
{
NSLog(@"Do this thing:");
if(message->payloadlen){
    const char *payload = (const char *)message->payload;
    [array addObject:[NSString stringWithUTF8String: payload]];
    //[self performSelectorOnMainThread:@selector(updateTable) withObject:nil waitUntilDone:NO];        

    //printf("%s %s\n", message->topic, message->payload);
}else{
    //printf("%s (null)\n", message->topic);
}
//fflush(stdout);

}

Thanks

  • 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-26T14:31:12+00:00Added an answer on May 26, 2026 at 2:31 pm

    The function mosquitto_new takes a void * pointer as the second argument, which it will then pass to any callbacks that you have. You can use that to pass self as the thing that should arrive at your callback as void *obj. It’s then explicitly safe to cast that to the correct [pointer to] class type since C allows any pointer type to be converted to void * (and back) without any side effects.

    So then you’d do something like:

    void my_message_callback(void *obj, struct mosquitto_message *message)
    {
        [(ClassType *)obj
            performSelectorOnMainThread:@selector(updateTable)
            withObject:nil
            waitUntilDone:NO];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using a powerful library called TiMidity, which I'm sure many iPhone developers have
I am using a library function called get_count_and_price which returns a 2-tuple (count,price). In
Im using opensource library called wxFreeChart to draw some XY charts. In example there
I am using a library called EXIFextractor to extract metadata information from images. This
What I want to do is to create a new shared library called libxxx
I get this error when using some library called: Mcrypt extension: Fatal error: Uncaught
I'm using a JavaScript library called phpjs The goal is to create functions that
I am trying to send a message using PHPs mail library called Swiftmailer .
I'm working on a HTML5 canvas game using a JavaScript library called Propulsionjs.com. The
We are using Tesseract OCR Java library called Tess4J. It works fine if run

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.