OneSignal Flutter 在 MacOS Sonoma 14.0 和 iOS 17.0 开发者测试版上。

huangapple go评论97阅读模式
英文:

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

  1. 在 pubspec.yaml 中安装 onesignal_flutter: ^5.0.0-beta2

  2. 修改 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
  1. 更新 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)
        }
    }
    
}
  1. 将顺序更改为与我的相同。

  2. 我已将 ios 部署目标到处更改为 14(但我不确定是否必要)。

英文:
  1. Install onesignal_flutter: ^5.0.0-beta2 in pubspec.yaml

  2. 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
    
    
  3. 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)
            }
        }
    
    }
    
    
  4. change the order here to the same as mine
    OneSignal Flutter 在 MacOS Sonoma 14.0 和 iOS 17.0 开发者测试版上。

  5. I changed the ios deployment target everywhere to 14 (but I don't know for sure if this is necessary)

huangapple
  • 本文由 发表于 2023年6月16日 03:14:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76484858.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定