最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ios - After disabling permission to access geolocation, local critical notification does not arrive - Stack Overflow

programmeradmin7浏览0评论

My application has permission to display critical notifications (remote and local). The application has logic configured to display critical notifications at a certain interval if the application is in the background

                    Log.i(">noti #\(i) next \(i * self.preEpisodeInterval)s")
                    self.scheduleLocalNoti(
                        title: LanguageHelper.getTranslationByKey(LanguageKey.ALARM) ?? "",
                        body: data.preEpisodeWarnMessage ?? "",
                        isCritical: true,
                        timeInterval: TimeInterval(i * self.preEpisodeInterval),
                        soundName: self.preAlarmModel?.data?.preEpisodeTone ?? "melodie.wav",
                        userInfo: [MotionTrackingManager.LOCAL_NOTI_PREALARM_USERINFO: ""]
                    )
    private func scheduleLocalNoti(title: String,
                                   body: String,
                                   isCritical: Bool = false,
                                   timeInterval: TimeInterval = 0,
                                   soundName: String? = nil,
                                   userInfo: [AnyHashable: Any]? = nil) {
        let content = UNMutableNotificationContent()
        content.title = title
        content.body = body
        if isCritical {
            if soundName != nil {
                let notiSound = UNNotificationSoundName(rawValue: soundName!)
                content.sound = UNNotificationSound.criticalSoundNamed(notiSound, withAudioVolume: 1.0)
            } else {
                content.sound = UNNotificationSound.defaultCriticalSound(withAudioVolume: 1.0)
            }
        } else {
            if soundName != nil {
                let notiSound = UNNotificationSoundName(rawValue: soundName!)
                content.sound = UNNotificationSound(named: notiSound)
            } else {
                content.sound = UNNotificationSound.default
            }
        }
        if userInfo != nil {
            content.userInfo = userInfo!
        }

        // Create the trigger
        let trigger = UNTimeIntervalNotificationTrigger(timeInterval: timeInterval + 1, repeats: false)

        let uuidString = UUID().uuidString

        Log.i("Schedule local noti for: \(timeInterval + 1) with uuid: \(uuidString)")
        // Create the request
        let request = UNNotificationRequest(
            identifier: uuidString,
            content: content,
            trigger: trigger
        )

        // Schedule the request with the system.
        let notificationCenter = UNUserNotificationCenter.current()
        notificationCenter.add(request) { error in
            if error != nil {
                // Handle any errors.
                Log.e("errr: \(String(describing: error?.localizedDescription))")
            }
        }
    }

The application also has logic that requires geolocation tracking with the Background Modes Location update mark in Signing & Capabilities. If permission to track geolocation is denied, the local notification is not displayed (with remote ones, it still works correctly).

What's also interesting: this ONLY happens with builds in testFlight/appStore. The release build on the emulator directly from XCode works correctly and continues to display the notification even when access to geolocation is denied

How can geolocation affect the display of local critical notifications?

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论