编写 NativeScript 插件的正确语法
Correct syntax for writing NativeScript plugin
我正在学习 NativeScript 插件并尝试让 PubNub iOS SDK 正常工作。到目前为止(使用下面的 TypeScript),我能够成功配置、订阅频道和发布消息。我也在尝试通过将“//处理新消息...”部分也转换为 TypeScript 来接收消息,但无法使其正常工作。这个怎么写?
Objective-C:
// Initialize and configure PubNub client instance
PNConfiguration *configuration = [PNConfiguration configurationWithPublishKey:@"demo" subscribeKey:@"demo"];
self.client = [PubNub clientWithConfiguration:configuration];
[self.client addListener:self];
// Subscribe to demo channel with presence observation
[self.client subscribeToChannels: @[@"my_channel"] withPresence:YES];
// Handle new message from one of channels on which client has been subscribed.
- (void)client:(PubNub *)client didReceiveMessage:(PNMessageResult *)message {
NSLog(@"Received message");
}
// Publish message
[self.client publish: @{@"message": @"this is my message"}
toChannel: @"my_channel" withCompletion:^(PNPublishStatus *status) {
}];
打字稿:
// Initialize and configure PubNub client instance
this.config = PNConfiguration.configurationWithPublishKeySubscribeKey("demo", "demo");
this.client = PubNub.clientWithConfiguration(this.config);
this.client.addListener();
// Subscribe to demo channel with presence observation
this.client.subscribeToChannelsWithPresence(channels, true);
// Handle new message from one of channels on which client has been subscribed.
?
// Publish message
this.client.publishToChannelWithCompletion(msgObj, channel, function(publishStatus) {
console.log(publishStatus.data)
})
我正在学习 NativeScript 插件并尝试让 PubNub iOS SDK 正常工作。到目前为止(使用下面的 TypeScript),我能够成功配置、订阅频道和发布消息。我也在尝试通过将“//处理新消息...”部分也转换为 TypeScript 来接收消息,但无法使其正常工作。这个怎么写?
Objective-C:
// Initialize and configure PubNub client instance
PNConfiguration *configuration = [PNConfiguration configurationWithPublishKey:@"demo" subscribeKey:@"demo"];
self.client = [PubNub clientWithConfiguration:configuration];
[self.client addListener:self];
// Subscribe to demo channel with presence observation
[self.client subscribeToChannels: @[@"my_channel"] withPresence:YES];
// Handle new message from one of channels on which client has been subscribed.
- (void)client:(PubNub *)client didReceiveMessage:(PNMessageResult *)message {
NSLog(@"Received message");
}
// Publish message
[self.client publish: @{@"message": @"this is my message"}
toChannel: @"my_channel" withCompletion:^(PNPublishStatus *status) {
}];
打字稿:
// Initialize and configure PubNub client instance
this.config = PNConfiguration.configurationWithPublishKeySubscribeKey("demo", "demo");
this.client = PubNub.clientWithConfiguration(this.config);
this.client.addListener();
// Subscribe to demo channel with presence observation
this.client.subscribeToChannelsWithPresence(channels, true);
// Handle new message from one of channels on which client has been subscribed.
?
// Publish message
this.client.publishToChannelWithCompletion(msgObj, channel, function(publishStatus) {
console.log(publishStatus.data)
})