[英]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.