Last active
December 12, 2015 10:29
-
-
Save paulmelnikow/4759361 to your computer and use it in GitHub Desktop.
Simple XMPPFramework test project
This file contains 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
#import "AppDelegate.h" | |
#import "XMPPFramework.h" | |
#import "DDASLLogger.h" | |
#import "DDTTYLogger.h" | |
#import "DDLog.h" | |
static const int ddLogLevel = LOG_LEVEL_VERBOSE; | |
NSString * const XMPPAuthenticationMethodPlain = @"Plain"; | |
NSString * const XMPPAuthenticationMethodDigestMD5 = @"Digest-MD5"; | |
NSString * const OptionHostName = @"..."; | |
NSUInteger const OptionPort = 5222; | |
BOOL const OptionOldSchoolSSL = NO; | |
NSString * const OptionJID = @"[email protected]"; | |
NSString * const OptionAuthenticationMethod = @"Plain"; | |
NSString * const OptionPassword = @"..."; | |
@interface AppDelegate () <XMPPStreamDelegate> | |
@property (retain) XMPPStream *xmppStream; | |
@end | |
@implementation AppDelegate | |
- (void)_setUpLogging { | |
[DDLog addLogger:[DDTTYLogger sharedInstance]]; | |
} | |
- (void)_setUpStream { | |
self.xmppStream = [[XMPPStream alloc] init]; | |
[self.xmppStream addDelegate:self delegateQueue:dispatch_get_main_queue()]; | |
self.xmppStream.hostName = OptionHostName; | |
self.xmppStream.hostPort = OptionPort; | |
self.xmppStream.myJID = [XMPPJID jidWithString:OptionJID]; | |
} | |
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { | |
[self _setUpLogging]; | |
[self _setUpStream]; | |
NSError *error = nil; | |
if (OptionOldSchoolSSL) | |
[self.xmppStream oldSchoolSecureConnect:&error]; | |
else | |
[self.xmppStream connect:&error]; | |
} | |
-(void)applicationWillTerminate:(NSNotification *)notification { | |
[self.xmppStream removeDelegate:self]; | |
[self.xmppStream disconnect]; | |
} | |
-(void)xmppStreamDidConnect:(XMPPStream *)sender { | |
Class authClass = nil; | |
if ([OptionAuthenticationMethod isEqual:XMPPAuthenticationMethodPlain]) | |
authClass = [XMPPPlainAuthentication class]; | |
else if ([OptionAuthenticationMethod isEqual:XMPPAuthenticationMethodDigestMD5]) | |
authClass = [XMPPDigestMD5Authentication class]; | |
else { | |
DDLogWarn(@"Unrecognized auhthentication method '%@', falling back on Plain", | |
OptionAuthenticationMethod); | |
authClass = [XMPPPlainAuthentication class]; | |
} | |
id<XMPPSASLAuthentication> auth = [[authClass alloc] initWithStream:sender | |
password:OptionPassword]; | |
NSError *error = nil; | |
if (![sender authenticate:auth error:&error]) | |
NSLog(@"Error authenticating: %@", error); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment