Skip to content
Browse files

CL-185: Remove error when phone wake.

  • Loading branch information...
1 parent 66ee7c4 commit 6e225e5fe8528e7ada3d680d93ed027ed30725e8 @tanaji-kadam tanaji-kadam committed Oct 17, 2012
View
2 objective-c/3.3/Pubnub/AppDelegate.m
@@ -8,6 +8,7 @@
#import "AppDelegate.h"
#import "iPhoneTest.h"
+#import "CEPubnub.h"
@implementation AppDelegate
@@ -24,6 +25,7 @@ - (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
+ [CEPubnub setApplicationActive:YES];
}
- (void)applicationDidEnterBackground:(UIApplication *)application
View
3 objective-c/3.3/Pubnub/PubNub/CEPubnub.h
@@ -78,7 +78,8 @@
- (void)presence:(NSString *)channel;
- (void)here_now:(NSString *)channel __deprecated;
-
++ (BOOL)isApplicationActive;
++ (void)setApplicationActive:(BOOL) state;
@end
@interface ChannelStatus :NSObject
View
24 objective-c/3.3/Pubnub/PubNub/CEPubnub.m
@@ -189,18 +189,28 @@ - (void)connection:(NSURLConnection*)connection didFailWithError:(NSError*)error
break;
default:
- [_pubNub connection:self didCompleteWithResponse:nil];
+ if(![CEPubnub isApplicationActive]){
+ [_pubNub connection:self didCompleteWithResponse:nil];
+ [CEPubnub setApplicationActive:NO];
+ }else
+ {
+ [_pubNub performSelector:@selector(_resubscribeToChannel:) withObject:_channel afterDelay:kMinRetryInterval];
+ }
+
break;
}
- NSLog(@"PubNub request failed with error: %@", error);
+
}
}
+- (void)connection:(NSURLConnection*)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge{
+}
@end
@implementation CEPubnub
@synthesize delegate=_delegate;
+ BOOL _appState;
- (CEPubnub *) initWithSubscribeKey:(NSString *)subscribeKey useSSL:(BOOL)useSSL {
return [self initWithPublishKey:nil subscribeKey:subscribeKey secretKey:nil useSSL:useSSL cipherKey:nil uuid:nil origin:kDefaultOrigin];
@@ -653,6 +663,16 @@ - (NSArray *)getDecryptedArray:(NSArray*)array
return messages;
}
++ (BOOL)isApplicationActive
+{
+ return _appState;
+}
+
++ (void)setApplicationActive:(BOOL)state
+{
+ _appState=state;
+}
+
- (void)connection:(PubNubConnection *)connection didCompleteWithResponse:(id)response {
switch (connection.command) {
case kCommand_SendMessage:
View
23 objective-c/3.3/Pubnub/iPhoneTest.m
@@ -21,13 +21,13 @@ -(id)getDelegate;
@implementation iPhoneTest
@synthesize txt;
-
+NSString *channelName;
CEPubnub *pubnub;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
-
+ channelName=@"hello_world";
pubnub = [[CEPubnub alloc] initWithPublishKey:@"demo" subscribeKey:@"demo" secretKey:nil cipherKey:nil useSSL:NO];
//subscribe to a few channels
@@ -50,24 +50,24 @@ - (IBAction)StringPublish:(id)sender {
NSLog(@"-----------PUBLISH STRING----------------");
NSString *text=@"Hello World";
- [pubnub publish:[NSDictionary dictionaryWithObjectsAndKeys:@"hello_world",@"channel",text,@"message", nil]];
+ [pubnub publish:[NSDictionary dictionaryWithObjectsAndKeys:channelName,@"channel",text,@"message", nil]];
}
- (IBAction)ArrayPublish:(id)sender {
NSLog(@"-----------PUBLISH ARRAY----------------");
- [pubnub publish:[NSDictionary dictionaryWithObjectsAndKeys:@"hello_world",@"channel",[NSArray arrayWithObjects:@"seven", @"eight", [NSDictionary dictionaryWithObjectsAndKeys:@"Cheeseburger",@"food",@"Coffee",@"drink", nil], nil],@"message", nil]];
+ [pubnub publish:[NSDictionary dictionaryWithObjectsAndKeys:channelName,@"channel",[NSArray arrayWithObjects:@"seven", @"eight", [NSDictionary dictionaryWithObjectsAndKeys:@"Cheeseburger",@"food",@"Coffee",@"drink", nil], nil],@"message", nil]];
}
- (IBAction)DictionaryPublish:(id)sender {
NSLog(@"-----------PUBLISH Dictionary----------------");
- [pubnub publish:[NSDictionary dictionaryWithObjectsAndKeys:@"hello_world",@"channel",[NSDictionary dictionaryWithObjectsAndKeys:@"X-code->ÇÈ°∂@#$%^&*()!",@"Editer",@"Objective-c",@"Language", nil],@"message", nil]];
+ [pubnub publish:[NSDictionary dictionaryWithObjectsAndKeys:channelName,@"channel",[NSDictionary dictionaryWithObjectsAndKeys:@"X-code->ÇÈ°∂@#$%^&*()!",@"Editer",@"Objective-c",@"Language", nil],@"message", nil]];
}
- (IBAction)HistoryClick:(id)sender {
NSLog(@"-----------HISTORY ----------------");
NSInteger limit = 3;
NSNumber * aWrappedInt = [NSNumber numberWithInteger:limit];
- [pubnub fetchHistory:[NSDictionary dictionaryWithObjectsAndKeys: aWrappedInt,@"limit", @"hello_world",@"channel",nil]];
+ [pubnub fetchHistory:[NSDictionary dictionaryWithObjectsAndKeys: aWrappedInt,@"limit", channelName,@"channel",nil]];
}
- (IBAction)TimeClick:(id)sender {
@@ -85,20 +85,20 @@ - (IBAction)unitTest:(id)sender {
}
- (IBAction)Subscribe:(id)sender {
- [pubnub subscribe: @"hello_world"];
+ [pubnub subscribe: channelName];
}
- (IBAction)Unsubscribe:(id)sender {
- [pubnub unsubscribeFromChannel: @"hello_world"];
+ [pubnub unsubscribeFromChannel: channelName];
}
- (IBAction)Here_Now:(id)sender {
- [pubnub hereNow: @"hello_world"];
+ [pubnub hereNow: channelName];
}
- (IBAction)Presence:(id)sender {
- [pubnub presence: @"hello_world"];
+ [pubnub presence: channelName];
}
- (IBAction)DetailedHistoryClick:(id)sender {
@@ -107,7 +107,7 @@ - (IBAction)DetailedHistoryClick:(id)sender {
NSNumber * aCountInt = [NSNumber numberWithInteger:count];
[pubnub detailedHistory:[NSDictionary dictionaryWithObjectsAndKeys:
aCountInt,@"count",
- @"hello_world",@"channel",
+ channelName,@"channel",
nil]];
}
@@ -377,4 +377,3 @@ - (void)pubnub:(CEPubnub *)pubnub reconnectToChannel:(NSString *)channel
@end
-

0 comments on commit 6e225e5

Please sign in to comment.
Something went wrong with that request. Please try again.