英文:
OneSignal Flutter on MacOS Sonoma 14.0 & iOS 17.0 Developer Beta
问题
我在开发者发布之前更新了所有我的设备,我的项目停止运行了。然而,我能够解决这个问题,并愿意分享解决方案给需要的人。
我的环境:
[✓] Flutter(稳定频道,3.10.4,在 macOS 14.0 23A5257q darwin-arm64 上,区域设置为 ru-RU)
[✓] Android 工具链 - 为 Android 设备开发(Android SDK 版本 33.0.2)
[✓] Xcode - 为 iOS 和 macOS 开发(Xcode 15.0)
[✓] Chrome - 为 web 开发
[✓] Android Studio(版本 2022.1)
[✓] VS Code(版本 1.79.1)
[✓] 已连接设备(3 台可用)
[✓] 网络资源
英文:
I updated all my devices before the developer release and my project stopped running. However, I was able to solve the problem and would like to share the solution for anyone who needs it.
My environment:
[✓] Flutter (Channel stable, 3.10.4, on macOS 14.0 23A5257q darwin-arm64, locale ru-RU)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 15.0)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.1)
[✓] VS Code (version 1.79.1)
[✓] Connected device (3 available)
[✓] Network resources
答案1
得分: 1
-
在 pubspec.yaml 中安装
onesignal_flutter: ^5.0.0-beta2
。 -
修改 ios/Podfile:
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
installer.generated_projects.each do |project|
project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '14.0'
end
end
end
end
target 'OneSignalNotificationServiceExtension' do
use_frameworks!
pod 'OneSignalXCFramework', '5.0.0-beta-04'
end
- 更新 ios/OneSignalNotificationServiceExtension/NotificationService.swift 文件(将所有的 OneSignal 替换为 OneSignalExtension)(我在这里找到的:https://github.com/OneSignal/OneSignal-iOS-SDK/releases/tag/3.11.0-beta-01):
import UserNotifications
import OneSignalExtension // 更新此处
class NotificationService: UNNotificationServiceExtension {
var contentHandler: ((UNNotificationContent) -> Void)?
var receivedRequest: UNNotificationRequest!
var bestAttemptContent: UNMutableNotificationContent?
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.receivedRequest = request
self.contentHandler = contentHandler
self.bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
if let bestAttemptContent = bestAttemptContent {
// 如果您的 SDK 版本小于 3.5.0,请取消注释并使用以下代码:
/*
OneSignal.didReceiveNotificationExtensionRequest(self.receivedRequest, with: self.bestAttemptContent)
contentHandler(bestAttemptContent)
*/
/* 调试:取消注释下面的两行以检查此扩展是否正在执行
注意,仅在设置 mutable-content 时才会运行此扩展
设置附件或操作按钮会自动添加此内容 */
//OneSignal.setLogLevel(.LL_VERBOSE, visualLevel: .LL_NONE)
//bestAttemptContent.body = "[Modified] " + bestAttemptContent.body
// 更新此处
OneSignalExtension.didReceiveNotificationExtensionRequest(self.receivedRequest, with: bestAttemptContent, withContentHandler: self.contentHandler)
}
}
override func serviceExtensionTimeWillExpire() {
// 在系统终止扩展之前调用。
// 利用此机会交付修改后内容的“最佳尝试”,否则将使用原始推送负载。
if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent {
// 更新此处
OneSignalExtension.serviceExtensionTimeWillExpireRequest(self.receivedRequest, with: self.bestAttemptContent)
contentHandler(bestAttemptContent)
}
}
}
-
将顺序更改为与我的相同。
-
我已将 ios 部署目标到处更改为 14(但我不确定是否必要)。
英文:
-
Install
onesignal_flutter: ^5.0.0-beta2
in pubspec.yaml -
Change ios/Podfile:
installer.pods_project.targets.each do |target| flutter_additional_ios_build_settings(target) end installer.generated_projects.each do |project| project.targets.each do |target| target.build_configurations.each do |config| config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '14.0' end end end end target 'OneSignalNotificationServiceExtension' do use_frameworks! pod 'OneSignalXCFramework', '5.0.0-beta-04' end
-
Update ios/OneSignalNotificationServiceExtension/NotificationService.swift (Replace all OneSignal with OneSignalExtension) (I found this here: https://github.com/OneSignal/OneSignal-iOS-SDK/releases/tag/3.11.0-beta-01):
import UserNotifications import OneSignalExtension // Update here class NotificationService: UNNotificationServiceExtension { var contentHandler: ((UNNotificationContent) -> Void)? var receivedRequest: UNNotificationRequest! var bestAttemptContent: UNMutableNotificationContent? override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) { self.receivedRequest = request self.contentHandler = contentHandler self.bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent) if let bestAttemptContent = bestAttemptContent { //If your SDK version is < 3.5.0 uncomment and use this code: /* OneSignal.didReceiveNotificationExtensionRequest(self.receivedRequest, with: self.bestAttemptContent) contentHandler(bestAttemptContent) */ /* DEBUGGING: Uncomment the 2 lines below to check this extension is excuting Note, this extension only runs when mutable-content is set Setting an attachment or action buttons automatically adds this */ //OneSignal.setLogLevel(.LL_VERBOSE, visualLevel: .LL_NONE) //bestAttemptContent.body = "[Modified] " + bestAttemptContent.body // Update here OneSignalExtension.didReceiveNotificationExtensionRequest(self.receivedRequest, with: bestAttemptContent, withContentHandler: self.contentHandler) } } override func serviceExtensionTimeWillExpire() { // Called just before the extension will be terminated by the system. // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used. if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent { // Update here OneSignalExtension.serviceExtensionTimeWillExpireRequest(self.receivedRequest, with: self.bestAttemptContent) contentHandler(bestAttemptContent) } } }
-
I changed the ios deployment target everywhere to 14 (but I don't know for sure if this is necessary)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论