我有一个问题要问通知。几个小时后,学习如何在iPhone上实现推送通知,它现在到了!
如何管理点击徽章或点击提醒视图的用户?用户点击那里会发生什么?
我试图以跳板增量向我发送一些通知和应用程序图标上的数字。以哪种方式点击它可以显示一个uiview来管理收到的通知并显示读取和未读的消息?
是否有教程?我想将所有消息保存在uitableview中。
答案 0 :(得分:34)
您想阅读Handling Local and Remote Notifications
基本上在您的应用程序委托中,您希望实现:
- (BOOL)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
和
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo;
处理通知数据的launchOptions / userInfo。
我通常如何处理数据:
- (BOOL)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSDictionary* userInfo =
[launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (userInfo) {
[self processRemoteNotification:userInfo];
}
[window addSubview:viewController.view];
[window makeKeyAndVisible];
return YES;
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[self processRemoteNotification:userInfo];
}
userInfo的格式记录在The Notification Payload部分。
e.g。 “aps”键会给你另一个NSDictionary,然后查找“alert”键会给你显示的警告信息。此外,您在JSON有效负载中发送的任何自定义数据也将存在。
NSDictionary *apsInfo = [userInfo objectForKey:@"aps"];
NSString *alertMsg = @"";
NSString *badge = @"";
NSString *sound = @"";
NSString *custom = @"";
if( [apsInfo objectForKey:@"alert"] != NULL)
{
alertMsg = [apsInfo objectForKey:@"alert"];
}
if( [apsInfo objectForKey:@"badge"] != NULL)
{
badge = [apsInfo objectForKey:@"badge"];
}
if( [apsInfo objectForKey:@"sound"] != NULL)
{
sound = [apsInfo objectForKey:@"sound"];
}
if( [userInfo objectForKey:@"Custom"] != NULL)
{
custom = [userInfo objectForKey:@"Custom"];
}