Running C code in an Objective-C thread (Cocoa) (for iOS)

First of all, I am a very new Objective C / Cocoa iOS Developer, but I used to write C / C ++ applications.

I managed to run the Rabbitmq-c client (http://hg.rabbitmq.com/rabbitmq-c/) inside my iPhone application, and I can connect directly to Rabbitmq from my application and even use the queue element, so everything is fine.

Now my problem is that my iPhone application needs to use the rabbitmq-c library to poll incoming messages from the server. There will probably be an endless loop.

Should I take this to a new thread? Ideally, I want to wrap the rabbitmq-c class as an object of the Async Object C class and use NSNotification (or something similar) to notify my user interface. I am a little inclined to create a new thread, since I read about materials such as Runloop, etc., It can solve many problems without using an additional thread.

What is best for me? Any examples of code or directions would be helpful. Please remember that I am not dealing with the Objective C / Coca rabbitmq library here, I am using C code in my iPhone application.

thank

Subrat

+3
source share
3 answers

Do not block the main thread when polling your server.

, . ( ) while. . .

, ( NSNotification) - UIKit .

, , NSRunLoop CFRunLoop.

+4

, UIKit.

, . ( ).

:

, . , , .

0

Or else you can write a method to receive messages. This method can have an infinite loop.

Later you can put this method in a background thread like this.

[self performSelectorInBackground: @selector (receiveMessages) withObject: nil];

0
source

Source: https://habr.com/ru/post/1789725/


All Articles