首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

如何在iOS remote通知上禁用默认通知警报视图?

在iOS上禁用默认通知警报视图,可以通过以下步骤实现:

  1. 在AppDelegate.swift文件中,找到didFinishLaunchingWithOptions方法。
  2. 在该方法中,添加以下代码来注册远程通知:
代码语言:txt
复制
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in
    if granted {
        DispatchQueue.main.async {
            UIApplication.shared.registerForRemoteNotifications()
        }
    }
}
  1. 在同一个文件中,添加以下方法来处理接收到的远程通知:
代码语言:txt
复制
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
    // 禁用默认通知警报视图
    completionHandler([])
}
  1. 在AppDelegate类中,添加UNUserNotificationCenterDelegate协议,并在didFinishLaunchingWithOptions方法中设置UNUserNotificationCenter.current().delegate = self

完整的代码示例:

代码语言:txt
复制
import UIKit
import UserNotifications

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in
            if granted {
                DispatchQueue.main.async {
                    UIApplication.shared.registerForRemoteNotifications()
                }
            }
        }
        
        UNUserNotificationCenter.current().delegate = self
        
        return true
    }
    
    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        // 禁用默认通知警报视图
        completionHandler([])
    }
}

这样,当应用程序在前台运行时,将不会显示默认的通知警报视图,而是可以自定义处理远程通知的展示方式。

页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

  • win2003服务器安全设置教程

    1.系统盘和站点放置盘必须设置为NTFS格式,方便设置权限. 2.系统盘和站点放置盘除administrators 和system的用户权限全部去除. 3.启用windows自带防火墙,只保留有用的端口,比如远程和Web,Ftp(3389,80,21)等等,有邮件服务器的还要打开25和130端口. 4.安装好SQL后进入目录搜索 xplog70 然后将找到的三个文件改名或者删除. 5.更改sa密码为你都不知道的超长密码,在任何情况下都不要用sa这个帐户. 6.改名系统默认帐户名并新建一个Administrator帐户作为陷阱帐户,设置超长密码,并去掉所有用户组.(就是在用户组那里设置为空即可.让这个帐号不属于任何用户组)同样改名禁用掉Guest用户. 7.配置帐户锁定策略(在运行中输入gpedit.msc回车,打开组策略编辑器,选择计算机配置-Windows设置-安全设置-账户策略-账户锁定策略,将账户设为“三次登陆无效”,“锁定时间30分钟”,“复位锁定计数设为30分钟”。) 8.在安全设置里 本地策略-安全选项 将 网络访问 :可匿名访问的共享 ; 网络访问:可匿名访问的命名管道 ; 网络访问:可远程访问的注册表路径 ; 网络访问:可远程访问的注册表路径和子路径 ; 以上四项清空. 9.在安全设置里 本地策略-安全选项 通过终端服务拒绝登陆 加入 ASPNET Guest IUSR_* IWAM_* NETWORK SERVICE SQLDebugger (*表示你的机器名,具体查找可以点击 添加用户或组 选 高级 选 立即查找 在底下列出的用户列表里选择. 注意不要添加进user组和administrators组 添加进去以后就没有办法远程登陆了.) 10.去掉默认共享,将以下文件存为reg后缀,然后执行导入即可.

    01
    领券