rih*_*ihe 7 objective-c pubnub parse-platform
我想将PubNub与Parse一起用于聊天模块.有人可以解释我如何通过PubNub向用户发送带有文本和图像的消息(只有一对一)?我想使用PFUser用户名作为用户私有频道的ID.
我在PubNub 帮助文档中找到了这段代码,但我从来没有在objective-c中看到这样的代码.我应该在哪里/如何使用这条线?
curl https://pubsub.pubnub.com/publish/<PUB-KEY>/<SUB-KEY>/0/<CHANNEL-NAME>/0/%22Hellooooooo%22
Run Code Online (Sandbox Code Playgroud)
我也不清楚我应该在哪里存储消息?在Parse还是我可以只在PubNub存储它们?我不确定第二种变化是否可行,因为我没有在PubNub上看到任何数据存储.或者例如我只发送我在Parse存储的PFObjects的url?
Ste*_*lum 10

您可以将解析云内的消息发布给移动用户,以便轻松创建聊天体验.如果要直接从Parse Cloud中发送消息,请使用以下代码向用户发送消息:
Parse.Cloud.httpRequest({
url: 'https://pubsub.pubnub.com/publish/<PUB-KEY>/<SUB-KEY>/0/<USER-CHANNEL-NAME>/0/%22Hellooooooo!%22',
// successful HTTP status code
success: function(httpResponse) {
console.log(httpResponse.text);
},
// unsuccessful HTTP status code
error: function(httpResponse) {
console.error('Request failed with response code ' + httpResponse.status);
}
});
Run Code Online (Sandbox Code Playgroud)
您不一定需要以这种方式使用Parse.您可以直接在用户之间向每个用户的频道名称发送消息.莎莉有"channel-sally",而比尔也有"channel-bill".您可以直接从Objective-C应用程序代码发布和订阅.Bill将订阅他自己的频道和Sally到她的频道.
// Define a channel
PNChannel *myChannel = [PNChannel channelWithName:@"channel-bob"];
PNChannel *friendChannel = [PNChannel channelWithName:@"channel-sally"];
// Receive Messages Sent to Me!
[PubNub subscribeOnChannel:myChannel];
// Send a Message to Sally
[PubNub sendMessage:@"Hello from PubNub iOS!" toChannel:friendChannel];
//(In AppDelegate.m, define didReceiveMessage delegate method:)
- (void)pubnubClient:(PubNub *)client didReceiveMessage:(PNMessage *)message {
NSLog(@"Received: %@", message.message);
}
Run Code Online (Sandbox Code Playgroud)
Bob可以在自己的频道上接收消息,并且可以向Sally或他的任何其他朋友发送消息.
| 归档时间: |
|
| 查看次数: |
1405 次 |
| 最近记录: |