首页 > 解决方案 > 用 Pyobjus 包装 Objective C

问题描述

我想使用 Pyobjus 在 Python 中包装以下目标 C,但我没有使用目标 C 的经验。我该怎么做呢?

// create the client with a unique client ID
NSString *clientID = ...
MQTTClient *client = [[MQTTClient alloc] initWithClientId:clientID];

// connect to the MQTT server
[self.client connectToHost:@"iot.eclipse.org" 
         completionHandler:^(NSUInteger code) {
    if (code == ConnectionAccepted) {
        // when the client is connected, send a MQTT message
        [self.client publishString:@"Hello, MQTT"
                           toTopic:@"/MQTTKit/example"
                           withQos:AtMostOnce
                            retain:NO
                 completionHandler:^(int mid) {
            NSLog(@"message has been delivered");
        }];
    }
}];

来自这里的代码

我查看了Pyobjus docsautoclass ,但是在将函数与类一起使用时出现错误MQTTClient

MQTTClient = autoclass("MQTTClient")给出错误Unable to find class b'MQTTClient'

标签: pythonobjective-c

解决方案


推荐阅读