iphone – 如何在用户点击徽章时管理通知

我有一个问题要问通知.几个小时后,学习如何在iPhone上实现推送通知,它现在到了!

如何管理点击徽章的用户或点击提醒视图?当用户点击那里时会发生什么?

我尝试以跳板增量向我发送一些通知和应用程序图标上的数字.以哪种方式点击它可以显示一个uiview来管理收到的通知并显示读取和未读的消息?

有没有它的教程?我想将所有消息保存在uitableview中.

最佳答案
你想阅读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部分.

例如“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"];
}

转载注明原文:iphone – 如何在用户点击徽章时管理通知 - 代码日志