当用户点击图标时,推送通知 iOS 7 不起作用 [英] PushNotifications iOS 7 not working when user taps on icon

查看:20
本文介绍了当用户点击图标时,推送通知 iOS 7 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下方法来处理推送通知.当应用程序运行时它们工作得很好,当应用程序在后台时我会收到通知.当用户点击图标时,它会打开应用程序,但我的 UICollection 视图不会像用户在应用程序运行时收到通知那样重新加载.

I have the methods below to handle push notifications. They work perfect when the app is running and I do receive notifications when the app is in the background. When a user taps the icon however it opens the app but my UICollection view is not reloaded the way it is when a user receives the notification when the app is running.

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    UIApplicationState state = [application applicationState];
    if (state == UIApplicationStateActive) {
        // do stuff when app is active
        NSString *cancelTitle = @"Close";
        NSString *showTitle = @"Ok";
        NSString *message = [[userInfo valueForKey:@"aps"] valueForKey:@"alert"];
        NSString *type = [userInfo objectForKey:@"type"];

        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Linkedstar"
                                                            message:message
                                                           delegate:self
                                                  cancelButtonTitle:cancelTitle
                                                  otherButtonTitles:showTitle, nil];

        if([type isEqualToString:@"message"]) {
            alertView.tag = alertMessage;
        }
        else if([type isEqualToString:@"post"]) {
            alertView.tag = post;
        }
        else if([type isEqualToString:@"contact"]) {
            alertView.tag = contact;
        }

        [alertView show];

        [self presentViewForPush:userInfo updateUI:YES];
    }
    else
    {
        // do stuff when app is in background
        NSLog(@"Received notification: %@", userInfo);
        [self handlePush:userInfo updateUI:YES];
    }
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    NSDictionary *pushDict = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
    if(pushDict)
    {
        [self handlePush:pushDict updateUI:YES];
    }
}

我需要帮助弄清楚当用户点击图标时如何处理 launchOptions 数据.我在网上做了一些研究但没有成功后尝试了几个不同的选项.任何帮助是极大的赞赏.谢谢.

I need help figuring out how to handle the launchOptions data when the user taps on the icon.I have tried a couple of different options after doing some research online and non worked. any help is greatly appreciated. Thank you.

推荐答案

你读过这个吗调度、注册和处理通知

如果点击操作按钮(在运行 iOS 的设备上),系统启动应用程序,应用程序调用其委托的应用程序:didFinishLaunchingWithOptions:方法(如果实现);它传入通知有效负载(用于远程通知)或本地通知对象(用于本地通知).

If the action button is tapped (on a device running iOS), the system launches the application and the application calls its delegate’s application:didFinishLaunchingWithOptions: method (if implemented); it passes in the notification payload (for remote notifications) or the local-notification object (for local notifications).

如果在运行 iOS 的设备上点击应用程序图标,应用程序调用相同的方法,但不提供任何信息通知

If the application icon is tapped on a device running iOS, the application calls the same method, but furnishes no information about the notification

这篇关于当用户点击图标时,推送通知 iOS 7 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆