菜鸟教程小白 发表于 2022-12-11 18:52:53

ios - 在应用商店中提交应用时本地通知不起作用


                                            <p><p>当我为我的应用程序提交更新时,本地通知不起作用。我已经在我的设备上进行了测试,它可以正常工作,但是当我从 AppStore 下载应用程序时,通知根本不起作用
这里的代码是 AppDelgate :</p>

<pre><code>    class AppDelegate: UIResponder, UIApplicationDelegate,UNUserNotificationCenterDelegate

@available(iOS 10.0, *)
    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -&gt; Void) {

    }
    @available(iOS 10.0, *)
    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -&gt; Void) {
      completionHandler([.alert,.sound])
    }
</code></pre>

<p>并且我已经实现了这段代码,以便在计时器击中发布日期时发送通知</p>

<pre><code>import UserNotifications
   let center = UNUserNotificationCenter.current()
      let options : UNAuthorizationOptions = [.alert, .sound, .badge]

            center.requestAuthorization(options: options) { (granted, error) in
                if !granted {
                  print(&#34;Somthing went wrong&#34;)

                }
            }

            center.getNotificationSettings { (settings) in
                if settings.authorizationStatus != .authorized {
                  print(&#34;Notification not allowd&#34;)
                }
            }

    here is in different function that calculate the time and send notification, I have not put the code for timer to make it more visual for others


   let content = UNMutableNotificationContent()
                content.title = NSLocalizedString(&#34;NOTIFICATION_TITLE&#34;, comment: &#34;Game Released&#34;)
                content.body = &#34;\(self.currentGame.gameName) Released ✌
页: [1]
查看完整版本: ios - 在应用商店中提交应用时本地通知不起作用