如何处理从解析接收到的推送通知? |的RSS [英] How to handle received push notification from parse ? | RSS

查看:64
本文介绍了如何处理从解析接收到的推送通知? |的RSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Parse,我的推送通知可以正常运行. 我的应用程序是RSS新闻提要,我不时发送推送通知",但问题是我不知道当用户收到推送通知时该如何处理. 我在plist文件中列出了所有RSS源,例如我的plist文件的外观:

Using Parse, my push notification working perfectly. my app is an RSS news feed, and from time to time I'm sending Push notification, my problem is that I don't know how to handle the push notification when the user receive it. I've got all my RSS sources listed in a plist file, for example how my plist file looks:

rss_sources

rss_sources

↓ 
01
  ↓
  url http://www.newyorkNews.com/rss.xml
  title: new york News
↓
02
  ↓
  url http://www.harlemNews.com/rss.xml
  title: harlem news

我想做的是,检查标题是否等于推送通知的开头(因为我是发送推送的人,所以我会写出准确的标题),以及是否然后它会转到我在代码中设置的index.row. 我甚至可能在这里提供什么? 如果有另一种方法,我将很高兴听到解决方案,或者与我的情况类似的某种代码模式,以便从中得到启发.

what i'm trying to do is, to check if the title is equal to the beginning of the push notification (since I'm the one who sending the push, i'll write the exact title), and if it does then it will go to some index.row that i set in code. is it even possible what I've offered here? if theres another way of doing it I will be glad to hear the solution, or some pattern of code that similar to my situation so I can get inspire from it.

推荐答案

您所要做的就是为有效负载设置一个通用密钥,在您的情况下,它看起来像标题.因此,当您发送推送(作为data/payload/json)时,当用户收到推送时,您会交叉引用valueForKey:

All you have to do is set a generic key to your payload which in your case looks like title. So when you send a push (as data/payload/json), when user receives one you cross reference the valueForKey:

一如既往,我强烈建议您自己尝试一些事情,因为这是您学习的方式.而且我总是将Parse用户引导到他们的文档中,因为他们的文档非常齐全.如果那是一件事,几乎也有记载.但是,如果遇到问题,这里是一个有效的示例:

As always, I highly encourage you try things out yourself because that's how you learn. And I always direct Parse users to their documentation because they are extremely well-documented. Almost too documented if that's a thing. However if you get stuck here is a working example:

使用有效负载构建推送:

Construct a push with payload:

NSDictionary *data = @{
@"alert" : @"some generic message here",
@"badge" : @"Increment",
@"sounds" : @"default",
@"title" : @"NY Times" //this is whatever you want
};

//schedule the push with some options. This isn't a mandatory set up, just an example. You can do a lot with PFPushes

PFPush *push = [[PFPush alloc] init];
[push setChannels:@[ @"subscribed" ]];
[push setData:data];
[push sendPushInBackground];

现在您所要做的就是查看有效载荷中关键字标题的值是否符合您的需求:

Now all you have to is see if the value in the payload for the key title matches your needs :

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  . . .
  // Extract the notification data from payload

 NSDictionary *notificationPayload = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];

 NSString *newsType = [notificationPayload valueForKey:@"title"];

  // perform segue or tab bar selectedIndex or whatever you want after checking if user is launching from notification :

if (notificationPayload) {
    //check it title has your string 
    if ([newsType isEqualToString:@"NY Times"]) {
         //do whatever here 
    } else {

    }
 }
}


参考-请自由使用这些参考,它们在向我们提供此最新资源方面做得很好

Parse iOS Push: https://parse.com/docs/push_guide#top/iOS

Parse iOS Push : https://parse.com/docs/push_guide#top/iOS

Parse SDK https://parse.com/docs/ios/api/

Parse SDK https://parse.com/docs/ios/api/

从解析控制台推送通知:

Push Notification from Parse console :

{
"aps" : {
    "alert" : "New NY Time Article",
    "badge" : 1,
    "sound" : "default",
    "title" : "NY Times"
        }
}

作为参考,这可以帮助您入门:

For reference this will get you started : https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW15

这篇关于如何处理从解析接收到的推送通知? |的RSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆