【问题标题】:Allow push notification popup not displayed允许不显示推送通知弹出窗口
【发布时间】:2018-04-03 01:26:05
【问题描述】:

我为 Android 和 IOS 开发了一个应用程序来接收推送通知,使用手机间隙推送插件。当我在 Android 设备上部署应用程序时,我能够接收推送通知。但是当我在 IOS 上部署应用程序并第一次运行应用程序时。我没有收到弹出窗口“允许推送通知”,这将允许应用程序接收推送通知。我想知道是否有人早些时候遇到过这个问题,或者有什么想法可以解决这个问题。 我在网上关注了几个帖子,但找不到与此相关的任何内容。根据我的理解,默认情况下应该由插件显示弹出窗口。

提前致谢。

【问题讨论】:

    标签: ios push-notification


    【解决方案1】:

    如果您使用 Objective-C,请使用以下代码:

    //  AppDelegate.m
    @import UserNotifications;
    

    之后,在方法“didFinishLaunchingWithOptions”中添加以下代码:

    if( SYSTEM_VERSION_LESS_THAN( @"10.0" ) )
    {
        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound |    UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
        [[UIApplication sharedApplication] registerForRemoteNotifications];
    
        if( optind != nil )
        {
            NSLog( @"registerForPushWithOptions:" );
        }
    }
    else
    {
        UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
        center.delegate = self;
        [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error)
         {
             if( !error )
             {
    
                 NSLog( @"Push registration success." );
             }
             else
             {
                NSLog(@"Something went wrong");
             }
         }];
    }
    

    如果您使用 swift,请阅读此https://useyourloaf.com/blog/local-notifications-with-ios-10/。我认为它对你有帮助。

    【讨论】:

    • 我既没有使用 Swift 也没有使用 Objective-c,我使用 IONIC 框架开发了应用程序。这应该适用于 IOS 和 Android。
    • 很遗憾,我对此一无所知。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-22
    • 2023-03-30
    相关资源
    最近更新 更多