热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

单击后为什么远程通知操作无效?-Whyremotenotificationactionisdoingnothingafterclicking?

IhaveconfiguredanactionforaremotenotificationwhenitarrivestomyiOsapp.Iwanttwodiff

I have configured an action for a remote notification when it arrives to my iOs app. I want two different actions whether one key passed in the payload. The code seems to be executed, but the app doesn't open, nor the safari url. Here is my AppDelegate.m:

我已经为远程通知配置了一个动作,当它到达我的iOs应用程序时。我想要两个不同的操作,无论一个密钥是否在有效负载中传代码似乎已执行,但应用程序无法打开,也不会打开safari网址。这是我的AppDelegate.m:

NSString *const NotificatiOnCategoryOpenView= @"openView";
NSString *const NotificatiOnActionOpenView= @"View";

- (void)registerForNotification {
    UIApplication *application = [UIApplication sharedApplication];

    // iOs 8 or greater:

    if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {

        UIMutableUserNotificationAction *open;
        open = [[UIMutableUserNotificationAction alloc] init];
        [open setActivationMode:UIUserNotificationActivationModeBackground];
        [open setTitle:NSLocalizedString(@"View", nil)];
        [open setIdentifier:NotificationActionOpenView];
        [open setDestructive:NO];
        [open setAuthenticationRequired:NO];

        UIMutableUserNotificationCategory *actionCategory;
        actiOnCategory= [[UIMutableUserNotificationCategory alloc] init];
        [actionCategory setIdentifier:NotificationCategoryOpenView];
        [actionCategory setActions:@[open] 
                        forContext:UIUserNotificationActionContextDefault];

        NSSet *categories = [NSSet setWithObject:actionCategory];
        UIUserNotificationType types = (UIUserNotificationTypeAlert|
                                        UIUserNotificationTypeSound|
                                        UIUserNotificationTypeBadge);

        UIUserNotificationSettings *settings;
        settings = [UIUserNotificationSettings settingsForTypes:types
                                                     categories:categories];

        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
    } else if ([application respondsToSelector:@selector(registerForRemoteNotificationTypes:)]) { 
        // iOs 7 or lesser:

        UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
        [application registerForRemoteNotificationTypes:myTypes];
    }

}

- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void (^)())completionHandler {

    if ([identifier isEqualToString:NotificationActionOpenView]) {

        NSDictionary *aps = userInfo[@"aps"];

        if ([[aps allKeys] containsObject:@"viewToOpen"]){
            NSString *webString = [[NSString alloc] initWithFormat:@"%@", aps[@"viewToOpen"]];
            NSURL *webURL = [[NSURL alloc] initWithString:webString];

// This line doesn't work:
            [[UIApplication sharedApplication] openURL:webURL];

        } else {
// These two lines doesn't work:
            UINavigationController *navigatiOnController= (UINavigationController *)self.window.rootViewController;
            [navigationController popToRootViewControllerAnimated:NO];
        }
    }

    completionHandler();

}

Thanks!

谢谢!

2 个解决方案

#1


0  

Implement

实行

- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void (^)())completionHandler 

And

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

Methods. Notification activation mode is set to UIUserNotificationActivationModeBackground,which Activate the app and put it in the background. If the app is already in the foreground, it remains in the foreground.So if you want to application in foreground/launch then use UIUserNotificationActivationModeForeground

方法。通知激活模式设置为UIUserNotificationActivationModeBackground,它激活应用程序并将其置于后台。如果应用程序已经在前台,它仍然在前台。所以如果你想在前台/启动中应用,那么使用UIUserNotificationActivationModeForeground

    [open setActivationMode:UIUserNotificationActivationModeBackground];

Use this activation option:

使用此激活选项:

    [open setActivationMode: UIUserNotificationActivationModeForeground];

Check weather webUrl is proper and working as expected in normal flow.

检查天气webUrl是否正常并在正常流程中按预期工作。

For Xcode 8, u will have to migrate push notification using UserNotification framework.

对于Xcode 8,您必须使用UserNotification框架迁移推送通知。

#2


1  

Your code should be in this method

您的代码应该使用此方法

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo  {

    if(userInfo) {
        UIApplicationState state = [[UIApplication sharedApplication] applicationState];
        NSUInteger notificatiOnType= [[userInfo valueForKey:API_NOTIFICATION_TYPE] integerValue];
        if (state == UIApplicationStateActive) {

            // Write code which should work when notification comes and app is active
            }
            else {
                // Write code which should work when notification comes and app is in background or inactive or terminated
            }
        }
    }
}

This method will get called only

此方法仅被调用

  1. when app is ACTIVE and notification comes
  2. 当应用程序处于活动状态且通知到来
  3. when app is in background or inactive or terminated and notifications comes and user taps on it
  4. 当应用程序处于后台或处于非活动状态或已终止时,通知会进入并且用户可以点击它

推荐阅读
  • vue使用
    关键词: ... [详细]
  • 云原生边缘计算之KubeEdge简介及功能特点
    本文介绍了云原生边缘计算中的KubeEdge系统,该系统是一个开源系统,用于将容器化应用程序编排功能扩展到Edge的主机。它基于Kubernetes构建,并为网络应用程序提供基础架构支持。同时,KubeEdge具有离线模式、基于Kubernetes的节点、群集、应用程序和设备管理、资源优化等特点。此外,KubeEdge还支持跨平台工作,在私有、公共和混合云中都可以运行。同时,KubeEdge还提供数据管理和数据分析管道引擎的支持。最后,本文还介绍了KubeEdge系统生成证书的方法。 ... [详细]
  • 本文讨论了使用差分约束系统求解House Man跳跃问题的思路与方法。给定一组不同高度,要求从最低点跳跃到最高点,每次跳跃的距离不超过D,并且不能改变给定的顺序。通过建立差分约束系统,将问题转化为图的建立和查询距离的问题。文章详细介绍了建立约束条件的方法,并使用SPFA算法判环并输出结果。同时还讨论了建边方向和跳跃顺序的关系。 ... [详细]
  • Android Studio Bumblebee | 2021.1.1(大黄蜂版本使用介绍)
    本文介绍了Android Studio Bumblebee | 2021.1.1(大黄蜂版本)的使用方法和相关知识,包括Gradle的介绍、设备管理器的配置、无线调试、新版本问题等内容。同时还提供了更新版本的下载地址和启动页面截图。 ... [详细]
  • Go GUIlxn/walk 学习3.菜单栏和工具栏的具体实现
    本文介绍了使用Go语言的GUI库lxn/walk实现菜单栏和工具栏的具体方法,包括消息窗口的产生、文件放置动作响应和提示框的应用。部分代码来自上一篇博客和lxn/walk官方示例。文章提供了学习GUI开发的实际案例和代码示例。 ... [详细]
  • 本文介绍了如何在使用emacs时去掉ubuntu的alt键默认功能,并提供了相应的操作步骤和注意事项。 ... [详细]
  • 本文介绍了Codeforces Round #321 (Div. 2)比赛中的问题Kefa and Dishes,通过状压和spfa算法解决了这个问题。给定一个有向图,求在不超过m步的情况下,能获得的最大权值和。点不能重复走。文章详细介绍了问题的题意、解题思路和代码实现。 ... [详细]
  • 本文介绍了Windows Vista操作系统中的用户账户保护功能,该功能是为了增强系统的安全性而设计的。通过对Vista测试版的体验,可以看到系统在安全性方面的进步。该功能的引入,为用户的账户安全提供了更好的保障。 ... [详细]
  • maven配置阿里云仓库的实现方法(2022年)_java
    本文主要介绍了maven配置阿里云仓库的实现方法,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的 ... [详细]
  • Monkey《大话移动——Android与iOS应用测试指南》的预购信息发布啦!
    Monkey《大话移动——Android与iOS应用测试指南》的预购信息已经发布,可以在京东和当当网进行预购。感谢几位大牛给出的书评,并呼吁大家的支持。明天京东的链接也将发布。 ... [详细]
  • Linux服务器密码过期策略、登录次数限制、私钥登录等配置方法
    本文介绍了在Linux服务器上进行密码过期策略、登录次数限制、私钥登录等配置的方法。通过修改配置文件中的参数,可以设置密码的有效期、最小间隔时间、最小长度,并在密码过期前进行提示。同时还介绍了如何进行公钥登录和修改默认账户用户名的操作。详细步骤和注意事项可参考本文内容。 ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • 在Android开发中,使用Picasso库可以实现对网络图片的等比例缩放。本文介绍了使用Picasso库进行图片缩放的方法,并提供了具体的代码实现。通过获取图片的宽高,计算目标宽度和高度,并创建新图实现等比例缩放。 ... [详细]
  • 我收到这个错误.我怎么能在我的情况下解决这个问题?Bitmapcannotberesolvedtoatype发生错误的行publicvoidonPageStart ... [详细]
  • Android NDK开发的一点尝试
    写在前面笔者是一个“原始”的C++开发者,对Java编程虽说不上抵触但也没有C++那么顺手。而且,作为一个游戏引擎,不管是在什么地方,效率总是第一位的,尤其是在移动平台这样资源吃紧 ... [详细]
author-avatar
榴莲味蛋筒
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有