Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

implementing didReceiveRemoteNotification for receiving messages whil…

…e in the foreground
  • Loading branch information...
commit b0259c301a9b920d9df3183f48eaaa2e5fc29efe 1 parent 4e047c8
authored November 27, 2012
34  objective-c/3.3/Pubnub/AppDelegate.m
@@ -43,6 +43,40 @@ - (void)application:(UIApplication*)application didRegisterForRemoteNotification
43 43
     
44 44
 }
45 45
 
  46
+
  47
+// This will fire if the application is running and in the foreground, and you receive an APNS notification
  48
+
  49
+- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
  50
+{
  51
+    NSString *message = nil;
  52
+    
  53
+    id alert = [userInfo objectForKey:@"aps"];
  54
+    
  55
+    NSLog(@"%@", userInfo);
  56
+    NSLog(@"%@", alert);
  57
+
  58
+    
  59
+    if ([alert isKindOfClass:[NSString class]]) {
  60
+        message = alert;
  61
+    } else
  62
+        
  63
+        if ([alert isKindOfClass:[NSDictionary class]]) {
  64
+        message = [alert objectForKey:@"alert"];
  65
+    }
  66
+    if (alert) {
  67
+        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Received while running in the foreground!"
  68
+                                                            message:message  delegate:self
  69
+                                                  cancelButtonTitle:@"Thanks PubNub!"
  70
+                                                  otherButtonTitles:nil];
  71
+        [alertView show];
  72
+        [self performSelector:@selector(byeAlert:) withObject:alertView afterDelay:2];
  73
+    }
  74
+}
  75
+
  76
+-(void)byeAlert:(UIAlertView*)x{
  77
+	[x dismissWithClickedButtonIndex:-1 animated:YES];
  78
+}
  79
+
46 80
 - (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
47 81
 {
48 82
 	NSLog(@"Failed to get token, error: %@", error);
2  objective-c/3.3/Pubnub/iPhoneTest.m
@@ -349,7 +349,7 @@ - (void) receivePubNubForegroundNotification:(NSNotification *) notification
349 349
     // as well.
350 350
     
351 351
     NSLog (@"Successfully received receivePubNubForegroundNotification!");
352  
-    NSString *message = [ [pubnub sessionUUID] stringByAppendingString:@" has joined the channel.";
  352
+    NSString *message = [ [pubnub sessionUUID] stringByAppendingString:@" has joined the channel."];
353 353
     
354 354
     [pubnub publish:[NSDictionary dictionaryWithObjectsAndKeys:channelName,@"channel", message, @"message", nil]];
355 355
 }

0 notes on commit b0259c3

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