OneSignal / OneSignal-Flutter-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your flutter app with OneSignal
https://www.onesignal.com
Other
606 stars 204 forks source link

[Bug]: Getting error when tryping to run on iOS17 - XCode 15 #746

Open dchandrani opened 9 months ago

dchandrani commented 9 months ago

What happened?

I updated my Xcode and migrated onesignal_flutter to 5.0.1. I have also updated pod file as instructed (pod 'OneSignalXCFramework', '>= 5.0.0', '< 6.0').

Still, I'm getting this error: Error (Xcode): Framework 'OneSignal' not found

Error (Xcode): Linker command failed with exit code 1 (use -v to see invocation)

Steps to reproduce?

1. Use XCode 15
2. Updated onesignal_flutter: ^5.0.1
3. Run project on simulator

What did you expect to happen?

You might encounter following error:

Failed to build iOS app Error (Xcode): Framework 'OneSignal' not found

Error (Xcode): Linker command failed with exit code 1 (use -v to see invocation)

Could not build the application for the simulator. Error launching application on iPhone 15.

OneSignal Flutter SDK version

5.0.1

Which platform(s) are affected?

Relevant log output

Xcode build done.                                           17.6s
Failed to build iOS app
Error (Xcode): Framework 'OneSignal' not found

Error (Xcode): Linker command failed with exit code 1 (use -v to see invocation)

Could not build the application for the simulator.
Error launching application on iPhone 15.

Code of Conduct

emawby commented 9 months ago

Hello I apologize we are working on updating our migration guide here. You likely need to update your import in your Notification Service Extension to be OneSignalFramework/OneSignalFramework.h

michael-joseph-payne commented 9 months ago

This has been an enormous time suck trying to migrate - and now I'm finding out the docs aren't finished yet.

emawby commented 9 months ago

@tgloc96 Interesting I am not able to reproduce that. The only similar issue I have found is this one in another SDK

ThakarRajesh commented 9 months ago

Hello @dchandrani I had the same problem. That is how I resolved it. Change OneSignal to OneSignalFramework in the NotificationService.swift file to make it work in my app. Screenshot 2023-09-25 at 2 40 30 PM

dchandrani commented 9 months ago

@ThakarRajesh It's not working in my case.

Screenshot 2023-09-25 at 3 28 13 PM
dchandrani commented 9 months ago

@ThakarRajesh Getting error Framework 'OneSignal' not found.

Screenshot 2023-09-25 at 3 33 31 PM
husainazkas commented 9 months ago

same here after upgrade xcode version to 15

emawby commented 9 months ago

That issue is usually with cocoapods having bad derived/cached data, however I would need to see your podfile to confirm.

However you also have the option of not using Cocoapods for the notification service extension target. You could try the following: Remove OneSignal from your NotificationServiceExtension section of your podfile completely. Then in Xcode navigate to the Notification Service Extension project settings and add the following XCFrameworks as dependencies: OneSignalCore.xcframework OneSignalOutcomes.xcframework OneSignalExtension.xcframework

image

It should now look like this

image
dchandrani commented 9 months ago

@emawby Did add the way you have mentioned. But still not able to build the project.

Screenshot 2023-09-27 at 10 16 19 PM
andj207 commented 9 months ago

Add like emawby mentioned and import OneSignalFramework works for me.

secretmoo35 commented 9 months ago

The same problem, and I looked at this, it works.

https://stackoverflow.com/questions/77187534/cycle-inside-project-building-could-produce-unreliable-results-cycle-details

emawby commented 9 months ago

@emawby Did add the way you have mentioned. But still not able to build the project.

Screenshot 2023-09-27 at 10 16 19 PM

Sorry like andj207 mentioned you also must import OneSignalFramework

temcewen commented 9 months ago

@emawby import OneSignalFramework in what file?

secretmoo35 commented 9 months ago

The same problem, and I looked at this, it works.

https://stackoverflow.com/questions/77187534/cycle-inside-project-building-could-produce-unreliable-results-cycle-details

  1. You can use OneSignal as is without the need to import anything additional.
  2. Open "TARGETS > Runner > Build Phases" and move "Embed Foundation Extensions" Above "Thin Binary"
Screenshot 2566-10-03 at 09 08 39 Screenshot 2566-10-03 at 09 08 28 Screenshot 2566-10-03 at 09 09 43
temcewen commented 9 months ago

@secretmoo35 I appreciate the response, but I had already tried that and it didn't work.

@emawby I was able to figure out what you meant by import OneSignalFramework, but I was using Objective-C instead of Swift at the time so I didn't figure it out till I tried to switch. It's working for me now. I do wonder what the import would have been for the Objective-C version.

sv-22 commented 9 months ago

Also having this issue on M1.

OneSignal integration is very frustrating, the amount of effort that we invested in constantly getting this thing to work has been massive. If this isn't resolved in timely manner we'll be switching.

temcewen commented 9 months ago

@shkvoretz Nobody can help you without specifics. Are you getting the exact same error: "'OneSignal' not found"?

If so, follow the instructions that @emawby said to do, use Swift instead of Objective-C for your Notification Service Extension, and then copy this code into the Notification.swift under the OneSignalNotificationServiceExtension folder:

import UserNotifications

import OneSignalFramework

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

            OneSignal.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 {
            OneSignal.serviceExtensionTimeWillExpireRequest(self.receivedRequest, with: self.bestAttemptContent)
            contentHandler(bestAttemptContent)
        }
    }

}
temcewen commented 9 months ago

OneSignal integration is very frustrating, the amount of effort that we invested in constantly getting this thing to work has been massive. If this isn't resolved in timely manner we'll be switching.

I know it seems difficult, but I think all notification service providers have a tough setup, and from what I've heard, OneSignal has the best service with one of the easiest setups. The issue is that they are doing a huge update from 3.x to 5.x. It's frustrating for sure, I spend 8 hours of a 12 hour day on fixing our implementation yesterday. However, the alternatives are probably worse, you're welcome to try them out though.

emawby commented 9 months ago

@shkvoretz Unfortunately these issues are with Cocoapods/NotificationServiceExtensions and are hard to debug if we cannot reproduce them. If none of the solutions in these threads have resolved your issue could you share a sample project that is experiencing the problem?

Vedsaga commented 1 month ago

In case it's Friday afternoon or anytime after 1am: Opening xcodeproj instead of xcworkspace will cause an error like this...

https://stackoverflow.com/questions/29500227/getting-error-no-such-module-using-xcode-but-the-framework-is-there

Solved it... Phew after 3 days