iOS推送通知消息 - 单击VIEW按钮后的操作

emi*_*mus 5 php push push-notification apple-push-notifications ios

我有推送通知的一些问题.我可以将它们发送到我注册的设备.一切正常.

我的问题是:点击VIEW按钮后,应用程序正在启动.目前没有任何内容.

我怎样才能在这里添加内容?此内容应取决于我发送的推送通知.

例如:我的推送通知是关于NEWS Number 1 - 然后在点击VIEW后我应该获得有关NEWS Number 1的更多信息

等等...

当从NEWS Number 1返回时,应该可以在列表中阅读应用程序中所有先前收到的NEWS.

你理解,我是什么意思?

我没有任何真正的想法...如果你能告诉我一个例子的代码会很好.

谢谢.

til*_*ilo 9

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

// 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
  }
Run Code Online (Sandbox Code Playgroud)

你可以在这里找到APNS知名教程:http://www.raywenderlich.com/3525/apple-push-notification-services-tutorial-part-2


Ole*_*ann 1

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

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