从C回调方法的Objective-C [英] Callback methods from C to Objective-C

查看:167
本文介绍了从C回调方法的Objective-C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Objective-C类。我做的是我在我的Objective-C类调用C函数[这个C函数我在一个文件,这是在这个样本的ios项目一部分实现。所有的C函数都工作正常,到目前为止,没有问题。

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 project]. All C functions are working fine , So far no issues.

当我尝试调用C文件异步函数,该函数将给予一段时间后,应对Objective-C类。我叫C函数指针,在Objective-C类正确触发。请检查以下code片段。我想做的回调方法一些UI相关的操作。那可能吗 ?如果没有有没有其他办法?你能不能请尽快给我respons。谢谢你。

When I try to call an asynchronous function in C file , that functions will give response to objective-c class after a while. I called function pointer in C which is triggered properly in Objective-C class. Please check the following code snippet. I want to do some UI related actions on the call back method. Is that possible ? If No is there any other way ? Could you please give me respons ASAP. Thanks.

C文件:

void my_int_func(int x);

void test_asyn_fun ()
{
    /* This code is for Sleep logic */
    for (int i=0; i<50000; i++) {
        // sleep
    }
    /* Sleep End */
    void (*foo)(int);
    foo = &my_int_func;
    foo(25);
}  

目标-C文件:

void my_int_func(int x) // this is call back method 
{
    printf( "%d\n", x ); // working properly 
    [self anyMethodInMyClass]; // I am unable to use self in this function.
}


其实我的要求是


Actually My requirement is

我对C code,这将做VoIP呼叫功能。
我从我的Objective-C [的iOS] code调用C函数。
如果呼叫已经由接收机我的C函数之一断开获取调用和停止的过程。但是还是我的UI是显示调用相关的UI。我想解雇了。

I have C code which will do a Voip call functionality. I am calling C functions from my objective-C [iOS] code. If call has been disconnected by the receiver one of my C function is getting called and it stops the process. But still my UI is showing calling related UI. I want to dismiss that.

在这里,我如何发送通知给我的Objective-C类从C函数驳回UIView的。任何一个可以好心帮我。

here , How do I send a notification to my objective-c class from C function to dismiss the UIView. Can any one kindly help me.

其实我使用的函数指针,但它不工作。

Actually i used function pointers but it's not working.

推荐答案

所有的感谢里卡多Kloth首先,现在是为我工作。

First of all Thanks to Ricardo Kloth , Now it's working for me.

下面是我的code ...

Here is my code ...

目标-C code:

static id staticObject = nil;

@Implementation MyObjCclass

init
{
    ....

    staticObject = self;
}

// C fun
void functionPointer() 
{ 
    [staticObject message]; // it's working 
}

-(void) message
{

}

@end

这篇关于从C回调方法的Objective-C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆