我的 iPhone 应用程序有什么方法可以获取发送给它的最后一个推送通知的内容吗?
基本上我想根据收到的通知类型执行特定的操作。
在推送通知中,您可以发送一个“有效负载”,该“有效负载”会在打开时传输到您的应用程序:
您的应用程序将获取“userInfo”(NSDictionary)作为 didFinishLaunchingWithOptions() 方法的参数。
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
Parameters
application
The application interested in the remote notification.
userInfo
A dictionary that contains information related to the remote notification, potentially including a badge number for the application icon, an alert sound, an alert message to display to the user, a notification identifier, and custom data. The provider originates it as a JSON-defined dictionary that iPhone OS converts to anNSDictionary object; the dictionary may contain only property-list objects plus NSNull.
要设置有效负载,请参阅Apple Push Notification Service Programming Guide。基本上,您可以在那里发送任何类型的信息,以帮助应用程序在内部将用户路由到正确的位置。