- Update
This commit is contained in:
1 parent
d281d765ea
commit
5b074a5176
1261 files changed
+199158
-7303
No files matched your search
@@ -0,0 +1,24 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
#import <UIKit/UIKit.h>
|
||||
#else
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#endif
|
||||
|
||||
#import "XMPPModule.h"
|
||||
|
||||
@interface XMPPSoftwareVersion : XMPPModule
|
||||
|
||||
@property (copy,readonly) NSString *name;
|
||||
@property (copy,readonly) NSString *version;
|
||||
@property (copy,readonly) NSString *os;
|
||||
|
||||
- (id)initWithDispatchQueue:(dispatch_queue_t)queue;
|
||||
|
||||
- (id)initWithName:(NSString *)name
|
||||
version:(NSString *)version
|
||||
os:(NSString *)os
|
||||
dispatchQueue:(dispatch_queue_t)queue;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,122 @@
|
||||
#import "XMPPSoftwareVersion.h"
|
||||
#import "XMPP.h"
|
||||
#import "XMPPFramework.h"
|
||||
|
||||
#if ! __has_feature(objc_arc)
|
||||
#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
|
||||
#endif
|
||||
|
||||
#define XMLNS_URN_XMPP_VERSION @"jabber:iq:version"
|
||||
|
||||
@implementation XMPPSoftwareVersion
|
||||
|
||||
@synthesize name = _name;
|
||||
@synthesize version = _version;
|
||||
@synthesize os = _os;
|
||||
|
||||
- (id)initWithDispatchQueue:(dispatch_queue_t)queue
|
||||
{
|
||||
NSString *name = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"];
|
||||
NSString *version = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
|
||||
#if TARGET_OS_IPHONE
|
||||
NSString *os = [NSString stringWithFormat:@"%@ %@",[[UIDevice currentDevice] systemName],[[UIDevice currentDevice] systemVersion]];
|
||||
#else
|
||||
NSString *os = [NSString stringWithFormat:@"OS X %@",[[NSProcessInfo processInfo] operatingSystemVersionString]];
|
||||
#endif
|
||||
|
||||
return [self initWithName:name version:version os:os dispatchQueue:queue];
|
||||
}
|
||||
|
||||
- (id)initWithName:(NSString *)name
|
||||
version:(NSString *)version
|
||||
os:(NSString *)os
|
||||
dispatchQueue:(dispatch_queue_t)queue
|
||||
{
|
||||
if ((self = [super initWithDispatchQueue:queue]))
|
||||
{
|
||||
NSAssert([name length], @"name MUST NOT be nil");
|
||||
NSAssert([version length], @"version MUST NOT be nil");
|
||||
|
||||
_name = [name copy];
|
||||
_version = [version copy];
|
||||
_os = [os copy];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)activate:(XMPPStream *)aXmppStream
|
||||
{
|
||||
if ([super activate:aXmppStream])
|
||||
{
|
||||
#ifdef _XMPP_CAPABILITIES_H
|
||||
[xmppStream autoAddDelegate:self delegateQueue:moduleQueue toModulesOfClass:[XMPPCapabilities class]];
|
||||
#endif
|
||||
return YES;
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)deactivate
|
||||
{
|
||||
#ifdef _XMPP_CAPABILITIES_H
|
||||
[xmppStream removeAutoDelegate:self delegateQueue:moduleQueue fromModulesOfClass:[XMPPCapabilities class]];
|
||||
#endif
|
||||
|
||||
[super deactivate];
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
#pragma mark XMPPStreamDelegate methods
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
- (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq
|
||||
{
|
||||
NSXMLElement *query = [iq elementForName:@"query" xmlns:XMLNS_URN_XMPP_VERSION];
|
||||
|
||||
if (query)
|
||||
{
|
||||
XMPPIQ *resultIQ = [XMPPIQ iqWithType:@"result" to:[iq from] elementID:[iq elementID]];
|
||||
|
||||
NSXMLElement *query = [NSXMLElement elementWithName:@"query" xmlns:XMLNS_URN_XMPP_VERSION];
|
||||
[resultIQ addChild:query];
|
||||
|
||||
NSXMLElement *nameElement = [NSXMLElement elementWithName:@"name" stringValue:self.name];
|
||||
[query addChild:nameElement];
|
||||
|
||||
NSXMLElement *versionElement = [NSXMLElement elementWithName:@"version" stringValue:self.version];
|
||||
[query addChild:versionElement];
|
||||
|
||||
if([self.os length])
|
||||
{
|
||||
NSXMLElement *osElement = [NSXMLElement elementWithName:@"os" stringValue:self.os];
|
||||
[query addChild:osElement];
|
||||
}
|
||||
|
||||
[xmppStream sendElement:resultIQ];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
#ifdef _XMPP_CAPABILITIES_H
|
||||
/**
|
||||
* If an XMPPCapabilites instance is used we want to advertise our support for XEP-0092.
|
||||
**/
|
||||
- (NSArray *)myFeaturesForXMPPCapabilities:(XMPPCapabilities *)sender
|
||||
{
|
||||
// This method is invoked on the moduleQueue.
|
||||
|
||||
// <query xmlns="http://jabber.org/protocol/disco#info">
|
||||
// ...
|
||||
// <feature var='urn:xmpp:jabber:iq:version'/>
|
||||
// ...
|
||||
// </query>
|
||||
|
||||
return @[XMLNS_URN_XMPP_VERSION];
|
||||
}
|
||||
#endif
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user