iOS 推送通知消息 - 单击“查看”按钮后的操作


iOS push notification message - action after clicking VIEW button

我在推送通知方面遇到了一些问题。我可以将它们很好地发送到我注册的设备。一切正常。

我的问题是:单击"查看"按钮后,应用程序正在启动。目前没有任何内容。

如何在此处添加内容?此内容应取决于我发送的推送通知。

例如:我的推送通知是关于新闻编号 1 - 然后单击"查看"后,我应该会获得有关新闻编号 1 的更多信息

等等...

此外,当从 NEWS 编号 1 返回时,应该可以在列表中阅读应用程序中所有以前收到的新闻。

你明白,我的意思吗?

我没有任何真正的想法...如果您能向我展示有关示例的代码,那就太好了。

谢谢。

只需实现以下代码,您就可以开始了:

// will be called if the app was not active
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [self applicationDidFinishLaunching:application];
    if (launchOptions != nil)
    {
        NSDictionary* dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
        if (dictionary != nil)
        {
            // get the necessary information out of the dictionary 
            // (the data you sent with your push message)
            // and load your data
        }
    }
    return YES;
}
// will be called when in foreground
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {    
    // get the necessary information out of the dictionary 
    // (the data you sent with your push message)
    // and load your data
  }

您可以在此处找到有关 APNS 的著名教程:http://www.raywenderlich.com/3525/apple-push-notification-services-tutorial-part-2

如果用户点击视图按钮时你的应用不在后台,则会调用application:didFinishLaunchingWithOptions:。该方法的第二个参数中的字典包含有关启动原因(直接、从推送或本地通知等)以及通知内容的信息。

如果你的应用已在后台运行,则在唤醒时会调用application:didReceiveRemoteNotification:。同样,第二个参数是包含通知内容的字典。

生成

通知的 UUID 时出错。您必须使用 __bridge_transfer 或 CFBridgingRelease,而不是使用 __bridge;否则CFStringRef将永远不会被发布。