2

I have a problem handling push message send with parse.com, when app is running i can handle json and construct message with:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

But when app is in background or killed, this message is handle and send direct to notification bar. I tried to handle in this function:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
....
 UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
    if (localNotif) {

        [[UIApplication sharedApplication] setApplicationIconBadgeNumber: 99];
        UIAlertView *BOOM = [[UIAlertView alloc] initWithTitle:@"BOOM"
                                                       message:@"app was INACTIVE"
                                                      delegate:self
                                             cancelButtonTitle:@"a-ha!"
                                             otherButtonTitles:nil];
        [BOOM show];
        NSLog(@"App was NOT ACTIVE");
    }
.....

est this responses, but i can't handle push messages:

Handling Push Notifications when App is NOT running

Can't handle push notifications when app is running background

Handling push notifications when app is not running (App is Killed)

how can I handle push notification when my app is not running

Any help ? Thx.

Community
  • 1
  • 1
fermin
  • 635
  • 7
  • 25

2 Answers2

0

I can't handle notifications when app is not running or in background, i change focus of resolution, i'm doing like android app's but i iOS handle messages with "Message Control" and i don't found "the way" to handle this.

I start to use channels of push notification for subscribe messages depending user settings. I send to Parse messages with channels, and app subscribe channels.

You can send Notification via POST:

  curl -X POST \
  -H "X-Parse-Application-Id: {APP-KEY}" \
  -H "X-Parse-REST-API-Key:   {REST-API-KEY}" \
  -H "Content-Type: application/json" \
  -d '{
        "channels": [
          "valencia",
          "sevilla"
        ],
        "data": {
          "alert": "Fin del partido Betis - Valencia 0-2",
          "sound": "gol.mp3"
        }
      }' \
  https://api.parse.com/1/push

In App you can subscribe to channels in AppDelegate:

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)newDeviceToken {
    // Store the deviceToken in the current installation and save it to Parse.
    PFInstallation *currentInstallation = [PFInstallation currentInstallation];
    [currentInstallation setDeviceTokenFromData:newDeviceToken];

    NSArray * channels = @[@"channel1", @"channel2"];
    NSLog(@"Channels : %@", channels);
    currentInstallation.channels = channels;
    [currentInstallation saveInBackground];
}

You can change channels anywhere, like this:

PFInstallation *currentInstallation = [PFInstallation currentInstallation];
currentInstallation.channels = @[@"channel3"];

[currentInstallation saveInBackground];

Maybe this can help someone.

fermin
  • 635
  • 7
  • 25
-1

Add your code to this function, when app is killed and you get push notification - it will call this function so that you can relaunch your app on this notification and show alert with in a application accordingly.

(void)application:(UIApplication *)app didReceiveRemoteNotification:(NSDictionary *)userInfo
CSchulz
  • 10,882
  • 11
  • 60
  • 114
  • I use this function when app is running, i can get JSON and create message. My problem is when app is not running, thx. – fermin Jan 20 '15 at 12:14
  • When app is not running this function will still be called but to activate your local notification and display alert in application, you need to relaunch your application otherwise when app is in kill state, you can not show alert using application code. – Nishant Sharma Jan 21 '15 at 05:43
  • I try removing app and then re-install but i have same problem, i rewrite message to show but it's not executed for this functions – fermin Jan 21 '15 at 08:11