0
点赞
收藏
分享

微信扫一扫

微信小程序通过点击事件跨页面传参以及data-方法传参(data-)

一天清晨 2023-12-22 阅读 23
ios

背景:

在iOS应用中,当应用在前台运行时,是不会默认弹出通知的。这是iOS的设计决定,以避免用户在使用应用的过程中被打扰。然而,如果你希望在应用在前台的时候也能收到通知,你可以在你的应用代码中进行一些修改。

添加代理

  1. 在AppDelegate的didFinishLaunchingWithOptions:方法中设置通知中心的代理
  2. 在你的AppDelegate中实现userNotificationCenter(_:willPresent:withCompletionHandler:)方法。
public func setNotifiAuth() {
        let center = UNUserNotificationCenter.current()
        center.delegate = self
        center.requestAuthorization(options: [.alert, .badge, .sound]) { granted, error in
            if granted == true {
                dePrint("允许通知")
            } else {
                dePrint("不允许通知")
            }
        }
    }
extension LocalNotification: UNUserNotificationCenterDelegate {
    // 前台显示弹窗
    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification) async -> UNNotificationPresentationOptions {
        return .alert
    }
}
举报

相关推荐

0 条评论