-
-
Save dbaba/b74882f147e1b8cf24ed to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
self.client = [[MQTTClient alloc]initWithClientId: @"iosapp" cleanSession:YES]; | |
self.client.username = @"sohta2@github"; | |
self.client.password = <パスワード>; | |
NSLog(@"publishToBroker!!!"); | |
NSLog(@"%@", gMQTTHost); | |
[self.client connectToHost:gMQTTHost completionHandler:^(NSUInteger code) { | |
NSLog(@"%lu", (unsigned long)code); | |
if(code == ConnectionAccepted) { | |
NSLog(@"connect accepted!"); | |
} else { | |
NSLog(@"mqtt broker return code:%lu", (unsigned long)code); | |
switch (code) { | |
case ConnectionRefusedUnacceptableProtocolVersion: | |
NSLog(@"connect error! code:%@", @"ConnectionRefusedUnacceptableProtocolVersion"); | |
break; | |
case ConnectionRefusedServerUnavailable: | |
NSLog(@"connect error! code:%@", @"ConnectionRefusedServerUnavailable"); | |
break; | |
case ConnectionRefusedBadUserNameOrPassword: | |
NSLog(@"connect error! code:%@", @"ConnectionRefusedBadUserNameOrPassword"); | |
break; | |
case ConnectionRefusedNotAuthorized: | |
NSLog(@"connect error! code:%@", @"ConnectionRefusedNotAuthorized"); | |
break; | |
default: | |
break; | |
} | |
NSLog(@"clientId: %@", self.clientId); | |
NSLog(@"username: %@", self.client.username); | |
NSLog(@"password: %@", self.client.password); | |
[self.client disconnectWithCompletionHandler:^(NSUInteger code) { | |
// The client is disconnected when this completion handler is called | |
NSLog(@"MQTT client is disconnected"); | |
}]; | |
self.client = nil; | |
return; | |
} | |
}]; | |
} | |
if (self.client) { | |
[self.client publishString:msg | |
toTopic: @"sohta2@github/example" | |
withQos:AtMostOnce | |
retain:YES | |
completionHandler:^(int mid) { | |
NSLog(@"mid:%d", mid); | |
NSLog(@"message has been delivered"); | |
} | |
]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment