【问题标题】:How to handle received push notification from parse ? | RSS如何处理从解析收到的推送通知? | RSS
【发布时间】:2015-05-10 01:36:25
【问题描述】:

使用 Parse,我的推送通知运行良好。 我的应用程序是一个 RSS 新闻提要,有时我会发送推送通知,我的问题是当用户收到推送通知时我不知道如何处理它。 我在 plist 文件中列出了我所有的 RSS 源,例如我的 plist 文件的外观:

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 。 我在这里提供的东西有可能吗? 如果有另一种方法,我会很高兴听到解决方案,或者一些类似于我的情况的代码模式,这样我就可以从中得到启发。

【问题讨论】:

    标签: objective-c parse-platform push-notification rss


    【解决方案1】:

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

    与往常一样,我强烈建议您亲自尝试,因为这就是您学习的方式。而且我总是将 Parse 用户引导到他们的文档,因为它们的文档非常好。如果那是一件事,几乎记录得太多了。但是,如果您卡在这里是一个工作示例:

    使用有效负载构造推送:

    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];
    

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

    - (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 {
    
        }
     }
    }
    

    参考资料 - 请随意使用这些参考资料,他们为我们提供了最新的资源,他们做得很好

    解析 iOS 推送:https://parse.com/docs/push_guide#top/iOS

    解析SDKhttps://parse.com/docs/ios/api/


    从 Parse 控制台推送通知:

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

    作为参考,这将帮助您入门:https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW15

    【讨论】:

    • 感谢您的详细回复。我读过解析文档,但我不得不承认 JSON 部分不清楚,可能是因为我不熟悉它。我不明白为什么要使用有效负载构建推送,因为我在 Parse 网站上发送通知,所以它是纯文本或 JSON。你放在这里的代码可能是我问题的答案,但让我做对了,我可以在 Parse 站点上发送 JSON 消息,然后执行你在 didFinishLanuchingWithOptions 中所做的逻辑?
    • @XcodeNOOB 简短回答,是的,总结一下。您可以使用任何一种方式,纯文本或 json 只需在 parse.com 控制台中选择相应的选项卡并相应地应用即可。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多