Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added events to have notifications while connect/disconnect/reconnect,

fixed issue for didFailPublishingMessageToChannel method
  • Loading branch information...
commit c68277135dc801c8b1dda6bf463c14102859542a 1 parent 1900623
raju authored
59 objective-c/Pubnub/PubNub/CEPubnub.h
View
@@ -28,43 +28,46 @@
- (void)pubnub:(CEPubnub *)pubnub subscriptionDidReceiveString:(NSString *)message onChannel:(NSString *)channel;
- (void)pubnub:(CEPubnub *)pubnub subscriptionDidFailWithResponse:(NSString *)message onChannel:(NSString *)channel;
-
-
- (void) pubnub:(CEPubnub*)pubnub didFetchHistory:(NSArray*)messages forChannel:(NSString*)channel; // "messages" will be nil on failure
- (void) pubnub:(CEPubnub*)pubnub didReceiveTime:(NSTimeInterval)time; // "time" will be NAN on failure
+
+- (void) pubnub:(CEPubnub*)pubnub ConnectToChannel:(NSString*)channel ;
+- (void) pubnub:(CEPubnub*)pubnub DisconnectToChannel:(NSString*)channel ;
+- (void) pubnub:(CEPubnub*)pubnub Re_ConnectToChannel:(NSString*)channel ;
@end
// All operations happen on the main thread
// Messages must be JSON compatible
@interface CEPubnub : NSObject {
@private
- id<CEPubnubDelegate> _delegate;
- NSString* _publishKey;
- NSString* _subscribeKey;
- NSString* _secretKey;
- NSString* _host;
- NSString* _cipherKey;
-
- NSMutableSet* _connections;
+ id<CEPubnubDelegate> _delegate;
+ NSString* _publishKey;
+ NSString* _subscribeKey;
+ NSString* _secretKey;
+ NSString* _host;
+ NSString* _cipherKey;
+
+ NSMutableSet* _connections;
+ NSMutableSet * _subscriptions;
}
@property(nonatomic, assign) id<CEPubnubDelegate> delegate;
- (CEPubnub*) initWithSubscribeKey:(NSString*)subscribeKey useSSL:(BOOL)useSSL;
- (CEPubnub*) initWithPublishKey:(NSString*)publishKey
- subscribeKey:(NSString*)subscribeKey
- secretKey:(NSString*)secretKey
- useSSL:(BOOL)useSSL;
+ subscribeKey:(NSString*)subscribeKey
+ secretKey:(NSString*)secretKey
+ useSSL:(BOOL)useSSL;
- (CEPubnub*) initWithPublishKey:(NSString*)publishKey // May be nil if -publishMessage:toChannel: is never used
- subscribeKey:(NSString*)subscribeKey
- secretKey:(NSString*)secretKey // May be nil if -publishMessage:toChannel: is never used
- useSSL:(BOOL)useSSL
- cipherKey:(NSString*)cipherKey
- origin:(NSString*)origin;
+ subscribeKey:(NSString*)subscribeKey
+ secretKey:(NSString*)secretKey // May be nil if -publishMessage:toChannel: is never used
+ useSSL:(BOOL)useSSL
+ cipherKey:(NSString*)cipherKey
+ origin:(NSString*)origin;
- (CEPubnub*) initWithPublishKey:(NSString*)publishKey
- subscribeKey:(NSString*)subscribeKey
- secretKey:(NSString*)secretKey
- cipherKey:(NSString*)cipherKey
- useSSL:(BOOL)useSSL;
+ subscribeKey:(NSString*)subscribeKey
+ secretKey:(NSString*)secretKey
+ cipherKey:(NSString*)cipherKey
+ useSSL:(BOOL)useSSL;
//- (void) publishMessage:(id)message toChannel:(NSString*)channel;
//- (void) fetchHistory:(NSUInteger)limit forChannel:(NSString*)channel;
@@ -80,3 +83,15 @@
- (void) unsubscribeFromChannel:(NSString*)channel; // Does nothing if not subscribed
- (BOOL) isSubscribedToChannel:(NSString*)channel;
@end
+
+struct ChannelStatus{
+ NSString *channel;
+ BOOL connected;
+ BOOL first;
+};
+
+@interface ChannelStatus :NSObject
+@property(nonatomic, retain) NSString* channel;
+@property(nonatomic, nonatomic) BOOL connected;
+@property(nonatomic, nonatomic) BOOL first;
+@end
264 objective-c/Pubnub/PubNub/CEPubnub.m
View
@@ -50,6 +50,10 @@ @interface CEPubnub ()
- (void) connection:(PubNubConnection*)connection didCompleteWithResponse:(id)response;
@end
+@implementation ChannelStatus
+@synthesize connected,channel,first;
+@end
+
@implementation PubNubConnection
@synthesize command=_command, channel=_channel, data=_data;
@@ -153,7 +157,6 @@ - (CEPubnub*) initWithPublishKey:(NSString*)publishKey
return self;
}
-
- (CEPubnub*) initWithPublishKey:(NSString*)publishKey
subscribeKey:(NSString*)subscribeKey
secretKey:(NSString*)secretKey
@@ -164,7 +167,6 @@ - (CEPubnub*) initWithPublishKey:(NSString*)publishKey
}
-
- (void) dealloc {
for (PubNubConnection* connection in _connections) {
[connection cancel];
@@ -180,8 +182,6 @@ - (void) dealloc {
[super dealloc];
}
-
-
-(NSDictionary*) getEncryptedDictionary:(NSDictionary*)message
{
NSMutableDictionary *msg=[[NSMutableDictionary alloc] init];
@@ -216,9 +216,6 @@ -(NSString*) getEncryptedString:(NSString*)disc
return returnval;
}
-
-
-
-(NSArray*) getEncryptedArray:(NSArray*)array
{
@@ -274,7 +271,6 @@ - (void) publish:(NSDictionary * )arg1{
msg=[self getEncryptedDictionary:(NSDictionary *)message ];
}
-
NSString* json = JSONWriteString(msg);
NSString* signature;
@@ -287,28 +283,71 @@ - (void) publish:(NSDictionary * )arg1{
[channel urlEscapedString], [json urlEscapedString]];
PubNubConnection* connection = [[PubNubConnection alloc] initWithPubNub:self
- url:[NSURL URLWithString:url]
- command:kCommand_SendMessage
- channel:channel];
+
[_connections addObject:connection];
[connection release];
}
-
-
-
-
- (void) _resubscribeToChannel:(NSString*)channel timeToken:(NSString*)timeToken {
+
+ BOOL is_disconnect= NO;
+ for (ChannelStatus* it in [[_subscriptions copy]autorelease]) {
+ if ([it.channel isEqualToString:channel])
+ {
+ if(!it.connected) {
+
+ NSLog(@"Disconnected to channel %@",channel);
+ if ([_delegate respondsToSelector:@selector(pubnub:DisconnectToChannel:forChannel:)]) {
+ [_delegate pubnub:self DisconnectToChannel:channel];
+ }
+
+ is_disconnect = YES;
+ break;
+ }
+ }
+ }
+
+ if (is_disconnect)
+ return;
+
NSString* url = [NSString stringWithFormat:@"%@/subscribe/%@/%@/0/%@", _host, _subscribeKey, [channel urlEscapedString], timeToken];
PubNubConnection* connection = [[PubNubConnection alloc] initWithPubNub:self
- url:[NSURL URLWithString:url]
- command:kCommand_ReceiveMessage
- channel:channel];
+
[_connections addObject:connection];
[connection release];
}
- (void) _resubscribeToChannel:(NSString*)channel {
+ // Ensure Single Connection
+ if (!_subscriptions && [_subscriptions count] > 0) {
+
+ BOOL channel_exist = NO;
+
+ for (ChannelStatus* it in [[_subscriptions copy]autorelease]) {
+ if ([it.channel isEqualToString:channel])
+ { channel_exist = YES;
+ break;
+ }
+ }
+
+ if (!channel_exist) {
+ ChannelStatus *cs = [[ChannelStatus alloc] init];
+ cs.channel = channel;
+ cs.connected = YES;
+ [_subscriptions addObject:cs];
+ } else {
+ // error_cb.execute("Already Connected");
+ return;
+ }
+ } else {
+ // New Channel
+ ChannelStatus *cs = [[ChannelStatus alloc] init];
+ cs.channel = channel;
+ cs.connected = true;
+ _subscriptions = [[NSMutableSet alloc] init];
+ [_subscriptions addObject:cs];
+
+ }
[self _resubscribeToChannel:channel timeToken:kInitialTimeToken];
}
@@ -331,6 +370,15 @@ - (void) unsubscribeFromChannel:(NSString*)channel {
}
}
[NSObject cancelPreviousPerformRequestsWithTarget:self];
+
+ for (ChannelStatus* it in [[_subscriptions copy]autorelease]) {
+ if ([it.channel isEqualToString:channel])
+ {
+ it.connected=false;
+ it.first=false;
+ break;
+ }
+ }
}
- (BOOL) isSubscribedToChannel:(NSString*)channel {
@@ -339,6 +387,14 @@ - (BOOL) isSubscribedToChannel:(NSString*)channel {
return YES;
}
}
+ for (ChannelStatus* it in [[_subscriptions copy]autorelease]) {
+ if ([it.channel isEqualToString:channel])
+ {
+ it.connected=false;
+ it.first=false;
+
+ }
+ }
return NO;
}
@@ -353,7 +409,6 @@ - (void) fetchHistory:(NSUInteger)limit forChannel:(NSString*)channel {
[self fetchHistory:disc];
}
-
- (void) fetchHistory:(NSDictionary * )arg1 {
int limit;
NSString* channel;
@@ -378,8 +433,6 @@ - (void) fetchHistory:(NSDictionary * )arg1 {
channel=[arg1 objectForKey:@"channel"];
}
-
-
if (limit > kMaxHistorySize) {
NSLog(@"PubNub history too large: %i", limit);
}
@@ -460,20 +513,27 @@ -(NSArray*) getDecryptedArray:(NSArray*)array
return messages;
}
-
-
-
- (void) connection:(PubNubConnection*)connection didCompleteWithResponse:(id)response {
+ NSDecimalNumber* timeTokanLocal=0;
switch (connection.command) {
case kCommand_SendMessage: {
BOOL success = NO;
NSString* error = nil;
- if ([response isKindOfClass:[NSArray class]] && ([response count] == 2)) {
- // NSLog(@"------> %@",response);
- success = [[response objectAtIndex:0] boolValue];
- if (success == NO) {
- error = [response objectAtIndex:1];
+
+ if(response)
+ {
+ if ([response isKindOfClass:[NSArray class]])
+ {
+ NSArray *arra= (NSArray*)response;
+ if([arra count] > 2)
+ {
+ success = [[arra objectAtIndex:0] boolValue];
+ if(success == NO)
+ {
+ error = [arra objectAtIndex:1];
+ }
+ }
}
}
if (success) {
@@ -482,8 +542,11 @@ - (void) connection:(PubNubConnection*)connection didCompleteWithResponse:(id)re
[_delegate pubnub:self didSucceedPublishingMessageToChannel:connection.channel];
}
} else {
- if (response) {
+ if (error) {
NSLog(@"Failed sending message to PubNub channel \"%@\": %@", connection.channel, error);
+ }else {
+ error= [NSString stringWithFormat:@"Failed sending message to PubNub channel \"%@\":", connection.channel];
+
}
if ([_delegate respondsToSelector:@selector(pubnub:didFailPublishingMessageToChannel:error:)]) {
[_delegate pubnub:self didFailPublishingMessageToChannel:connection.channel error:error];
@@ -494,6 +557,135 @@ - (void) connection:(PubNubConnection*)connection didCompleteWithResponse:(id)re
case kCommand_ReceiveMessage: {
NSString* timeToken = nil;
+
+ BOOL is_disconnect= NO;
+ for (ChannelStatus* it in [[_subscriptions copy]autorelease]) {
+ if ([it.channel isEqualToString:connection.channel])
+ {
+ if(!it.connected) {
+
+ NSLog(@"Disconnected to channel %@",connection.channel);
+ if ([_delegate respondsToSelector:@selector(pubnub:DisconnectToChannel:)]) {
+ [_delegate pubnub:self DisconnectToChannel:connection.channel];
+ }
+
+ is_disconnect = YES;
+ break;
+ }
+ }
+ }
+
+ if (is_disconnect)
+ return;
+ // timeToken = [response objectAtIndex:1];
+
+ // Problem?
+ if (response == nil || [timeToken isEqualToString:@"0"] ) {
+ for (ChannelStatus* it in [[_subscriptions copy]autorelease]) {
+ if ([it.channel isEqualToString:connection.channel])
+ {
+ [_subscriptions removeObject:it];
+ NSLog(@"_Disconnected to channel %@",connection.channel);
+ if ([_delegate respondsToSelector:@selector(pubnub:DisconnectToChannel:)]) {
+ [_delegate pubnub:self DisconnectToChannel:connection.channel];
+ }
+ }
+ }
+
+ // Ensure Connected (Call Time Function)
+ BOOL is_reconnected = NO;
+ while(1) {
+ //[self getTime];
+ NSString* url = [NSString stringWithFormat:@"%@/time/0", _host];
+ NSURLRequest * urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
+ NSURLResponse * response1 = nil;
+ NSError * error = nil;
+ NSData * data = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response1 error:&error];
+ NSLog(@"Responce::%@",response1);
+ NSLog(@"Data::%@",[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]);
+
+ NSDecimalNumber* time_token = 0;
+ // if(error != nil)
+ {
+ NSArray* resp= (NSArray *)JSONParseData(data);
+
+
+ if ([resp isKindOfClass:[NSArray class]] && ([resp count] == 1)) {
+ NSLog(@"Retrieved PubNub time '%@'", [resp objectAtIndex:0]);
+ time_token = [resp objectAtIndex:0];
+ }
+ }
+
+ if (time_token == 0) {
+ // Reconnect Callback
+
+ if ([_delegate respondsToSelector:@selector(pubnub:Re_ConnectToChannel:)]) {
+ NSLog(@"_Reconnecting to channel %@",connection.channel);
+ [_delegate pubnub:self Re_ConnectToChannel:connection.channel];
+ }
+
+ [NSThread sleepForTimeInterval:5];
+
+ } else {
+
+ if (!_subscriptions && [_subscriptions count] > 0) {
+
+ BOOL channel_exist = NO;
+
+ for (ChannelStatus* it in [[_subscriptions copy]autorelease]) {
+ if ([it.channel isEqualToString:connection.channel])
+ { channel_exist = YES;
+ break;
+ }
+ }
+
+ if (!channel_exist) {
+ ChannelStatus *cs = [[ChannelStatus alloc] init];
+ cs.channel = connection.channel;
+ cs.connected = YES;
+ [_subscriptions addObject:cs];
+ } else {
+ // error_cb.execute("Already Connected");
+ return;
+ }
+ } else {
+ // New Channel
+ ChannelStatus *cs = [[ChannelStatus alloc] init];
+ cs.channel = connection.channel;
+ cs.connected = true;
+ _subscriptions = [[NSMutableSet alloc] init];
+ [_subscriptions addObject:cs];
+ }
+
+ [self _resubscribeToChannel:connection.channel timeToken: [[NSString alloc]initWithFormat:@"%d",time_token]];
+ is_reconnected = YES;
+ break;
+ }
+ }
+ if(is_reconnected) {
+ break;
+ }
+ }
+ else {
+ for (ChannelStatus* it in [[_subscriptions copy]autorelease]) {
+ if ([it.channel isEqualToString:connection.channel])
+ {
+ // Connect Callback
+ if (it.first == NO) {
+ it.first = YES;
+ // connect_cb.execute("Connected to channel : "+channel);
+
+ //reconnect_cb.execute("Reconnecting to channel : "+connection.channel);
+ if ([_delegate respondsToSelector:@selector(pubnub:ConnectToChannel:)]) {
+ NSLog(@"_Connected to channel %@",connection.channel);
+ [_delegate pubnub:self ConnectToChannel:connection.channel];
+ }
+ break;
+ }
+ }
+ }
+ }
+
if ([response isKindOfClass:[NSArray class]] && ([response count] == 2)) {
NSLog(@"Received %i messages from PubNub channel \"%@\"", [[response objectAtIndex:0] count], connection.channel);
for (id message in [response objectAtIndex:0]) {
@@ -505,8 +697,7 @@ - (void) connection:(PubNubConnection*)connection didCompleteWithResponse:(id)re
[_delegate pubnub:self subscriptionDidReceiveDictionary:disc onChannel:connection.channel];
}
-
-
+
}else if ([message isKindOfClass:[NSArray class]]) {
if ([_delegate respondsToSelector:@selector(pubnub:subscriptionDidReceiveArray:onChannel:)]) {
NSArray * arr=[self getDecryptedArray:(NSArray *)message];
@@ -521,6 +712,7 @@ - (void) connection:(PubNubConnection*)connection didCompleteWithResponse:(id)re
[_delegate pubnub:self subscriptionDidReceiveString:str onChannel:connection.channel];
}
+
}else {
if ([_delegate respondsToSelector:@selector(pubnub:subscriptionDidFailWithResponse:onChannel:onChannel:)]) {
@@ -529,8 +721,7 @@ - (void) connection:(PubNubConnection*)connection didCompleteWithResponse:(id)re
}
}
}
-
-
+
timeToken = [response objectAtIndex:1];
} else if (response) {
NSLog(@"Unexpected subscribe response from PubNub");
@@ -569,8 +760,7 @@ - (void) connection:(PubNubConnection*)connection didCompleteWithResponse:(id)re
}
}
-
-
+
history = mainArray;
} else if (response) {
NSLog(@"Unexpected history response from PubNub");
@@ -586,8 +776,10 @@ - (void) connection:(PubNubConnection*)connection didCompleteWithResponse:(id)re
if ([response isKindOfClass:[NSArray class]] && ([response count] == 1)) {
NSLog(@"Retrieved PubNub time '%@'", [response objectAtIndex:0]);
number = [response objectAtIndex:0];
+ timeTokanLocal = number;
} else if (response) {
NSLog(@"Unexpected time response from PubNub");
+ timeTokanLocal=0;
}
if ([_delegate respondsToSelector:@selector(pubnub:didReceiveTime:)]) {
[_delegate pubnub:self didReceiveTime:(number ? [number doubleValue] : NAN)];
81 objective-c/Pubnub/README.md
View
@@ -1,81 +0,0 @@
-# Pubnub
----
-
-Pubnub is an iOS Objective-C library wrapper for the Pubnub realtime messaging service [Pubnub.com](http://www.pubnub.com/).
-
-## Using Pubnub in your project
-
-0. Add the Cipher.h/m,Base64.h/m,JSONKit.h/m,JSONE.h/m and Common.h/m supported file to your project
-
-1. Add CEPubnub.h/.m to your project
-
-2. Import CEPubnub.h to your class header
-
- #import "CEPubnub.h"
-
-3. Make your class follow the PubNubDelegate protocol
-
- @interface iPhoneTest : UIViewController <CEPubnubDelegate>
-
-4. Implement the CEPubnubDelegate methods (they are all optional):
-
- - (void) pubnub:(CEPubnub*)pubnub didSucceedPublishingMessageToChannel:(NSString*)channel;
- - (void) pubnub:(CEPubnub*)pubnub didFailPublishingMessageToChannel:(NSString*)channel error:(NSString*)error;
- - (void)pubnub:(CEPubnub *)pubnub subscriptionDidReceiveDictionary:(NSDictionary *)message onChannel:(NSString *)channel;
- - (void)pubnub:(CEPubnub *)pubnub subscriptionDidFailWithResponse:(NSString *)message onChannel:(NSString *)channel;
- - (void)pubnub:(CEPubnub *)pubnub subscriptionDidReceiveString:(NSString *)message onChannel:(NSString *)channel;
- - (void)pubnub:(CEPubnub *)pubnub subscriptionDidReceiveArray:(NSArray *)message onChannel:(NSString *)channel;
- - (void) pubnub:(CEPubnub*)pubnub didFetchHistory:(NSArray*)messages forChannel:(NSString*)channel;
- - (void) pubnub:(CEPubnub*)pubnub didReceiveTime:(NSTimeInterval)time;
-
-
-5. Instantiate Pubnub in your class so you can publish and subscribe to messages and assign delegate:self:
-
- pubnub = [[CEPubnub alloc] initWithPublishKey:@"demo" subscribeKey:@"demo" secretKey:@"demo" cipherKey:@"demo" useSSL:NO];
- [pubnub setDelegate:self];
-
-6. Publish NSString:
-
- NSString * text=@"My name is pubnub";[pubnub publish:[NSDictionary dictionaryWithObjectsAndKeys:@"hello_world",@"channel",text,@"message", nil]];
-
-7. Publish NSArray:
-
- [pubnub publish:[NSDictionary dictionaryWithObjectsAndKeys:@"hello_world",@"channel",[NSArray arrayWithObjects:@"seven", @"eight",
- [NSDictionary dictionaryWithObjectsAndKeys:@"Cheeseburger",@"food",@"Coffee",@"drink", nil], nil],@"message", nil]];
-
-
-8. Publish NSDictionaries:
-
- [pubnub publishMessage:[NSDictionary dictionaryWithObjectsAndKeys:
- @"hello_world",@"channel",
- [NSDictionary dictionaryWithObjectsAndKeys:@"X-code->ÇÈ°∂@#$%^&*()!",@"Editer",@"Objective-c",@"Language", nil],@"message",
- nil]];
-
-9. Subscribe to multiple message channels:
-
- [pubnub subscribe: @"hello_world_1"];
- [pubnub subscribe: @"hello_world_2"];
- [pubnub subscribe: @"hello_world_3"];
-
-10. Get a history of messages on a channel:
-
- NSInteger limit = 3;
- NSNumber * aWrappedInt = [NSNumber numberWithInteger:limit];
- [pubnub fetchHistory:[NSDictionary dictionaryWithObjectsAndKeys: aWrappedInt,@"limit", @"hello_world",@"channel",nil]];
-
-
-
-11. Get the time, Time receive in NSTimeInterval:
-
- [pubnub getTime];
-
-12. Get the Unique UUID:
-
- NSLog(@"UUID::: %@",[CEPubnub getUUID]);
-
-13. That's it! An example iPad app has been included in the project.
-
-## Author
-
-
-
19 objective-c/Pubnub/iPhoneTest.m
View
@@ -22,7 +22,7 @@ - (void)viewDidLoad
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
- pubnub = [[CEPubnub alloc] initWithPublishKey:@"demo" subscribeKey:@"demo" secretKey:@"demo" cipherKey:@"demo" useSSL:NO];
+ pubnub = [[CEPubnub alloc] initWithPublishKey:@"demo" subscribeKey:@"demo" secretKey:@"demo" cipherKey:@"" useSSL:NO];//(Cipher key is Optional)
//subscribe to a few channels
[pubnub setDelegate:self];
@@ -155,6 +155,23 @@ - (void) pubnub:(CEPubnub*)pubnub didReceiveTime:(NSTimeInterval)time{
[txt setText:[NSString stringWithFormat:@"Time :- received:\n %f", time]];
} // "time" will be NAN on failure
+- (void) pubnub:(CEPubnub*)pubnub ConnectToChannel:(NSString *)channel{
+ NSLog(@"ConnectToChannel ");
+ NSLog(@"Connect to Channel: %@",channel);
+ // [txt setText:[NSString stringWithFormat:@"Connect to Channel: %@",channel]];
+}
+
+- (void) pubnub:(CEPubnub*)pubnub DisconnectToChannel:(NSString *)channel{
+ NSLog(@"DisconnectToChannel ");
+ NSLog(@"Disconnect to Channel: %@",channel);
+ // [txt setText:[NSString stringWithFormat:@"Disconnect to Channel: %@",channel]];
+}
+- (void) pubnub:(CEPubnub*)pubnub Re_ConnectToChannel:(NSString *)channel{
+ NSLog(@"Re_ConnectToChannel ");
+ NSLog(@"Re-Connect to Channel: %@",channel);
+ //[txt setText:[NSString stringWithFormat:@"Connect to Channel: %@",channel]];
+}
+
- (void)dealloc {
[txt release];
[txt release];
20 objective-c/README.md
View
@@ -15,7 +15,7 @@ Pubnub is an iOS Objective-C library wrapper for the Pubnub realtime messaging s
3. Make your class follow the PubNubDelegate protocol
- @interface iPhoneTest : UIViewController <CEPubnubDelegate>
+ @interface iPhoneTest : UIViewController <CEPubnubDelegate>
4. Implement the CEPubnubDelegate methods (they are all optional):
@@ -27,11 +27,14 @@ Pubnub is an iOS Objective-C library wrapper for the Pubnub realtime messaging s
- (void)pubnub:(CEPubnub *)pubnub subscriptionDidReceiveArray:(NSArray *)message onChannel:(NSString *)channel;
- (void) pubnub:(CEPubnub*)pubnub didFetchHistory:(NSArray*)messages forChannel:(NSString*)channel;
- (void) pubnub:(CEPubnub*)pubnub didReceiveTime:(NSTimeInterval)time;
+ - (void) pubnub:(CEPubnub*)pubnub ConnectToChannel:(NSString*)channel ;
+ - (void) pubnub:(CEPubnub*)pubnub DisconnectToChannel:(NSString*)channel ;
+ - (void) pubnub:(CEPubnub*)pubnub Re_ConnectToChannel:(NSString*)channel ;
5. Instantiate Pubnub in your class so you can publish and subscribe to messages and assign delegate:self:
- pubnub = [[CEPubnub alloc] initWithPublishKey:@"demo" subscribeKey:@"demo" secretKey:@"demo" cipherKey:@"demo" useSSL:NO];
+ pubnub = [[CEPubnub alloc] initWithPublishKey:@"demo" subscribeKey:@"demo" secretKey:@"demo" cipherKey:@"" useSSL:NO];
[pubnub setDelegate:self];
6. Publish NSString:
@@ -53,9 +56,9 @@ Pubnub is an iOS Objective-C library wrapper for the Pubnub realtime messaging s
9. Subscribe to multiple message channels:
- [pubnub subscribeToChannel: @"hello_world_1"];
- [pubnub subscribeToChannel: @"hello_world_2"];
- [pubnub subscribeToChannel: @"hello_world_3"];
+ [pubnub subscribe: @"hello_world_1"];
+ [pubnub subscribe: @"hello_world_2"];
+ [pubnub subscribe: @"hello_world_3"];
10. Get a history of messages on a channel:
@@ -69,13 +72,8 @@ Pubnub is an iOS Objective-C library wrapper for the Pubnub realtime messaging s
[pubnub getTime];
-12. Get the Unique UUID:
+12. Get UUID:
NSLog(@"UUID::: %@",[CEPubnub getUUID]);
13. That's it! An example iPad app has been included in the project.
-
-## Author
-
-
-
Please sign in to comment.
Something went wrong with that request. Please try again.