项目作者: IT-Aces

项目描述 :
Objective-C STOMP over WebSockets
高级语言: Objective-C
项目地址: git://github.com/IT-Aces/stomp-objc.git
创建时间: 2018-10-27T10:33:59Z
项目社区:https://github.com/IT-Aces/stomp-objc

开源协议:Apache License 2.0

下载


stomp-objc

ObjectiveC STOMP over WebSockets

Based on jetfire and WebsocketStompKit

Works on iOS12

Usage:

Init

  1. NSURL *websocketUrl = [NSURL URLWithString:@"wss://10.0.0.1"];
  2. self.client = [[STOMPClient alloc] initWithURL:websocketUrl webSocketHeaders:nil useHeartbeat:YES];

Connect

  1. - (void)connectWithCompletion:(void(^)(BOOL succeeded))completion {
  2. if (self.client && !self.client.connected) {
  3. dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
  4. [self.client connectWithLogin:nil
  5. passcode:nil
  6. completionHandler:^(STOMPFrame *_, NSError *error) {
  7. dispatch_async(dispatch_get_main_queue(), ^(void){
  8. if (completion) completion(error == nil);
  9. });
  10. if (error) {
  11. NSLog(@"%@", error);
  12. return;
  13. }
  14. }];
  15. });
  16. }
  17. }

Subscribe

  1. - (void)subscribeToTopic:(NSString *)topic messageHandler:(void(^)(NSString *message))messageHandler {
  2. if (topic && topic.length > 0 &&
  3. self.client && self.client.connected) {
  4. dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
  5. [self.client subscribeTo:topic
  6. messageHandler:^(STOMPMessage *message) {
  7. if (message && messageHandler) {
  8. dispatch_async(dispatch_get_main_queue(), ^(void){
  9. messageHandler([NSString stringWithFormat:@"%@", message]);
  10. });
  11. }
  12. }];
  13. });
  14. }
  15. }