ios - ios App本地通知未在生产中显示通知
问题描述
这是我的 AppDelegate.swift 文件代码:
我在这里调用了 showNotification():
override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
//call channel handler
controller = window?.rootViewController as? FlutterViewController
callChannel = FlutterMethodChannel(name: "com.nta.ntacall/calls",
binaryMessenger: controller.binaryMessenger)
callChannel.setMethodCallHandler({
(call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
// Note: this method is invoked on the UI thread.
guard call.method == "processCalls" else {
result(FlutterMethodNotImplemented)
return
}
//process call test
//self.processCalls()
})
GeneratedPluginRegistrant.register(with: self)
callObserver.setDelegate(self, queue: nil)
UNUserNotificationCenter.current().delegate = self
getLocation()
/calling the show notification method here
showNotification()
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
我在这里有这个 showNotification 方法:
func showNotification(){
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.alert, .sound]) { (granted, error) in
}
center.requestAuthorization(options: [.alert, .sound]) { (granted, error) in
}
//if not active state then show notification
let state = UIApplication.shared.applicationState
if state == .background {
print("App in Background")
}else if state == .active {
print("App in Foreground or Active")
}
if state == .background {
print("1")
print("CXCallState :Disconnected")
// Step 2: Create the notification content
let content = UNMutableNotificationContent()
content.title = "Please rate your last call"
content.body = "Tap to rate..."
//show notification
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: nil)
// Step 5: Register the request
center.add(request) { (error) in
// Check the error parameter and handle any errors
}
}
else{
processCalls()
}
}
它在开发、模拟器和真实设备中运行良好,但在应用程序商店中发布应用程序时没有显示通知?可能是什么原因?
解决方案
推荐阅读
- flutter - 如何在 Flutter Web 应用中设置页面描述?
- python - Pycharm通过脚本运行导入命令时无法导入torch,但可以在控制台导入使用
- django - 如何在 Django 中将 CharField 的查询集过滤为 Int?
- xml - 如何使用 XPath 从 XML 中的相似元素中读取多个嵌套节点?
- performance - 协程中的 waitforseconds 是否与 sephamore.WaitForSignal 相关?
- iis - IIS URL 重写存在非英文字符的问题
- c - Proper methods to Copy files/folders programmatically in C using POSIX functions
- linux-kernel - 平台设备和平台驱动链接
- php - How to convert string to boolean multiple condition in PHP
- java - Not able to map Json to java Object using Jackson and lombok