Advertisement
Guest User

Untitled

a guest
Jan 6th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. - (void)viewDidLoad {
  2. [super viewDidLoad];
  3. xmppStream = [[XMPPStream alloc] init];
  4. [xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()];
  5.  
  6. xmppStream.hostName = @"hostname";
  7. xmppStream.hostPort = 5222;
  8.  
  9. NSString *username = @"name@domainname.net";
  10. NSString *password = @"123456";
  11.  
  12. [xmppStream setMyJID:[XMPPJID jidWithString:username]];
  13.  
  14. NSError *error = nil;
  15. if (![xmppStream oldSchoolSecureConnectWithTimeout:XMPPStreamTimeoutNone error:&error])
  16. {
  17. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
  18. message:[NSString stringWithFormat:@"Can't connect to server %@", [error localizedDescription]]
  19. delegate:nil
  20. cancelButtonTitle:@"Ok"
  21. otherButtonTitles:nil];
  22. [alertView show];
  23. }
  24. }
  25.  
  26. - (IBAction)connectToXmpp:(id)sender {
  27.  
  28. NSLog(@"%hhd", [xmppStream isConnected]);
  29. NSError *error = nil;
  30.  
  31. if (![xmppStream authenticateWithPassword:@"123456" error:&error]) {
  32. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
  33. message:[NSString stringWithFormat:@"Can't authenticate %@", [error localizedDescription]]
  34. delegate:nil
  35. cancelButtonTitle:@"Ok"
  36. otherButtonTitles:nil];
  37. [alertView show];
  38. }
  39. [xmppStream sendElement:[XMPPPresence presence]];
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement