1

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
  • There needs to be a question here because Stack Overflow is a question-and-answer site. – President James K. Polk Jun 15 '23 at 19:18
  • 1
    @PresidentJamesK.Polk James K. Polk I answered my own question so that other users could find my solution and apply it in their projects. – Семён Титов Jun 15 '23 at 19:30
  • You don't have a question here. Questions end with a question mark ("?"). – President James K. Polk Jun 15 '23 at 19:35
  • @PresidentJamesK.Polk I understand that. but what is more important: that I help people with my decision or that I formalize this post correctly? I think this site was created to help programmers solve difficult problems. I have just helped programmers solve a difficult problem with my post, and this is the main thing – Семён Титов Jun 15 '23 at 20:20
  • Why does it have to be either/or? Why not just edit your "question" to turn it into a real question? Neither your title nor your question body give a hint as to what the problem is. – President James K. Polk Jun 15 '23 at 20:37

1 Answers1

1
  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 enter image description here

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

  • Are you able to run Flutter from command line tools or VSCode (not Xcode) with this? Related issue on GH Flutter repo: https://github.com/flutter/flutter/issues/128531 – abegehr Jul 18 '23 at 21:03
  • 1
    @abegehr I always run via VS Code. I am currently using Mac OS 13.4.1 and iOS 17.0 Beta, which does not allow me to run my application on a real device due to the lack of iOSDeviceSupport for version 17.0. I am waiting for the necessary files here https://github.com/filsv/iOSDeviceSupport I don't run my Flutter projects via xCode from the update to iOS 17 as this is not possible for me at the moment I hope I understood the essence of the question correctly and gave at least some useful information for you – Семён Титов Jul 20 '23 at 10:25