Callback methods from C to Objective-C

前端 未结 4 1296
伪装坚强ぢ
伪装坚强ぢ 2021-01-21 07:03

I have an Objective-C class. What I am doing is I am calling C functions in my objective-C class [ This C functions I implemented in one file , which is part in this sample ios

4条回答
  •  深忆病人
    2021-01-21 07:20

    I ran into this problem aswell. I assume you are using PJSIP for your VoIP app.

    What you want to do is create a pointer to the Objective-C class you'd like to send messages to. You already figured you cannot call Objective-C functions from your C callback.

    static YourObjCClass *objCClassPtr

    @property (nonatomic, retain) YourObjCClass *class

    When initializing said class, have the static pointer point to the Objective C object's pointer. (pointer to pointer to object)

    objCClassPtr = class;

    You are now able to send messages to the Objective-C object using [objCClassPtr message] from your C function as if you would write [class message]

    You can point to self the same way.

提交回复
热议问题