如何从c方法iOS调用Objective c方法

时间:2017-03-16 07:16:53

标签: ios objective-c c void

我想从c =>调用数据目标c(ios)。

下面我分享了我的代码截图。

I WANT TO CALL data from c => objective c

4 个答案:

答案 0 :(得分:0)

声明id referance变量

#import <Cocoa/Cocoa.h>

id refToSelf;

比使用

打电话
[refToSelf cameraCapture];

答案 1 :(得分:0)

到目前为止,你有正确的线条。但是你忘了在你的.c

中包含.h文件

假设您要cameraCapture()mycclass.c文件中调用mycclass.c方法。

#include "myiosclass.h" void cameraCapture(){ //your c code goes here... }

myiosclass.h

extern void cameraCapture();

myiosclass.m

-(void)myMethod { cameraCapture(); //Called your C method. //Rest of objective c code ... }

{
  "rtVisitInfoOpObjV1":{
  "version":"1",
  "visitorId":"vis1",
  "dwellTime":"0",
  "poiId":"poi1",
  "srId":"sr1",
  "zoneId":"zone1",
  "poiProximityConfidence":"0",
  "zoneProximityConfidence":"0",
  "poiPresenceConfidence":"15",
  "zonePresenceConfidence":"0",
  "normalizedTime":"1489574975000"
 }
}

希望它会对你有所帮助。

答案 2 :(得分:0)

将当前视图控制器作为c方法中的参数传递并使用

void CameraCaptureFromC(long cCameraClient,
                     const char *imageName,
                              void *object,
                  MasterViewController *vc) {
  NSLog(@"glfm:Camera Call");
  [vc addAllImages];
  //your code
}

答案 3 :(得分:0)

//
//  ViewController.m
//  test
//
//  Created by colorsMacBook on 16/03/17.
//  Copyright © 2017 colors software. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end



@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    someMethod();
}

void someMethod(){
    printf("test123\n");
    [ViewController someMethod2:@"Calling objective C Method from C  method"];
}
+(void)someMethod2:(id)sender{
    NSLog(@"Message: %@",sender);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end

控制台日志

test123 2017-03-16 13:22:02.858测试[1198:240019]消息:从C方法调用目标C方法