简体   繁体   English

当应用未运行时处理JSON推送通知解析

[英]Handle JSON push notification parse when app is not running

I have a problem handling push message send with parse.com, when app is running i can handle json and construct message with: 我在处理通过parse.com发送的推送消息时遇到问题,当应用程序运行时,我可以处理json并使用以下方法构造消息:

- (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: est这个回应,但我无法处理推播讯息:

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. 谢谢。

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. 当应用程序未运行或在后台运行时,我无法处理通知,我改变了分辨率的焦点,我的工作方式类似于android应用程序,但是我的iOS使用“消息控制”来处理消息,而我找不到“处理方式”这个。

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: 您可以通过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: 在App中,您可以在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. 也许这可以帮助某人。

当应用被终止并收到推送通知时,将代码添加到此函数中-它会调用此函数,以便您可以在此通知上重新启动应用并在应用中相应地显示警报。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iOS如何在应用程序处于前台时处理解析JSON推送通知 - iOS How to Handle Parse JSON Push Notification when App is in Foreground 在应用程序运行且打开通知栏时处理推送通知 - Handle push notification when app is running and notification tray is opened 应用未运行/应用终止时如何处理推送通知 - How to handle push notification when app is not running/app is terminated 应用未运行时如何处理推送通知? - How Can I Handle Push Notification When App Is Not Running? 当应用在后台运行时无法处理推送通知,收到推送但未点击横幅或警报 - Can't handle Push Notification when the app is running in Background, receives push but didn't click on the banner or alert 当应用程序处于后台或运行状态时,处理推送通知,而不是在应用程序终止时 - Handle push notification when app is in Background or Running state not when app is terminated 当应用程序在后台时处理 iOS 推送通知 - Handle iOS Push Notification when app in backgroud 当应用程序未运行或处于后台状态时,如何处理推送通知有效负载而不点击它 - How to handle push notification payload without tapping it when the app is in not running or background state 处于“未运行”状态时在iOS应用中推送通知 - Push notification in iOS app when “Not running” state 应用未运行时无法接收推送通知 - cannot receive push notification when app is not running
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM