Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot build on iOS #39

Closed
derBeukatt opened this issue Nov 17, 2020 · 10 comments
Closed

Cannot build on iOS #39

derBeukatt opened this issue Nov 17, 2020 · 10 comments
Labels
enhancement New feature or request

Comments

@derBeukatt
Copy link
Contributor

derBeukatt commented Nov 17, 2020

As the title states, i cannot build my app using your library on iOS.
Ich do not use the lib on iOS at all, i just need it for android and cannot exclude it from iOS build.

Environment:

  • MacOS 10.15.7
  • Flutter 1.22.4
  • XCode 12.1
  • lib version 0.0.5+2

It throws the following error:

awesome_notifications-0.0.5+2/ios/Classes/lib/SwiftAwesomeNotificationsPlugin.swift:104:17: error: parameter of 'messaging(:didReceiveRegistrationToken:)' has different optionality than required by protocol 'MessagingDelegate'
public func messaging(
messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
^
?
FirebaseMessaging.MessagingDelegate:2:19: note: requirement 'messaging(:didReceiveRegistrationToken:)' declared here
optional func messaging(
messaging: Messaging, didReceiveRegistrationToken fcmToken: String?)

Suggesting the parameter must be optional. I made it optional and unwrapped inside your swift plugin and the build succeeded. Maybe you can give more insight.

@derBeukatt
Copy link
Contributor Author

Hey there.

Is this just a specific problem for me or does anyone else run into this.

@rafaelsetragni
Copy link
Owner

I was unable to reproduce your error. What steps did you take to create your iOS app?

Try modifying the messaging method below in your local code:

public func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {

@derBeukatt
Copy link
Contributor Author

derBeukatt commented Nov 24, 2020

Hi. Thanks for your answer.

I was just normally building my app via "flutter clean" followed by "flutter build ios" and the error occured.
I already did modify the following code:

https://github.com/rafaelsetragni/awesome_notifications/blob/b3e4da96f0302fef43f4c801d819dad044021332/ios/Classes/lib/SwiftAwesomeNotificationsPlugin.swift#L104

public func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
        print("Firebase registration token: \(fcmToken)")

        let dataDict:[String: String] = ["token": fcmToken]
        NotificationCenter.default.post(name: Notification.Name("FCMToken"), object: nil, userInfo: dataDict)
        // TODO: If necessary send token to application server.
        // Note: This callback is fired at each app startup and whenever a new token is generated.
}

to the following

public func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
        if let unwrapped = fcmToken {
            print("Firebase registration token: \(unwrapped)")
            let dataDict:[String: String] = ["token": unwrapped]
            NotificationCenter.default.post(name: Notification.Name("FCMToken"), object: nil, userInfo: dataDict)
            // TODO: If necessary send token to application server.
            // Note: This callback is fired at each app startup and whenever a new token is generated.
        }
}

But I just don't know why I had to do this.

@rafaelsetragni
Copy link
Owner

rafaelsetragni commented Nov 24, 2020

You are rigth. My messaging method is deprecated, thats why you couldnt compile the final version in your app. I gonna update it.
Did you use another firebase services in your app? What version are they?

Edited:

I put your mod into my project and XCode complained back:

Parameter of 'messaging(_:didReceiveRegistrationToken:)' has different optionality than expected by protocol 'MessagingDelegate'
Remove '?'

image

Better! Do you wanna do a fork and send me this fix? Your name will be included as this project contributor.

@derBeukatt
Copy link
Contributor Author

derBeukatt commented Nov 25, 2020

You are rigth. My messaging method is deprecated, thats why you couldnt compile the final version in your app. I gonna update it.
Did you use another firebase services in your app? What version are they?

I use FirebaseMessaging 7.1.0. That is the version installed by cocoapods.

Better! Do you wanna do a fork and send me this fix? Your name will be included as this project contributor.

Does this mean you experience the same problem after updating to the above version?
If so, I gladly provide the fix. Just don't want to break it for somebody else.

Prepared the pull request. You can decide if you want to merge. Thanks for your answers.

@rafaelsetragni
Copy link
Owner

rafaelsetragni commented Nov 25, 2020

Im did not experienced this issue. For me, when i applied your changes, XCode complains about the override operation not being possible due to the different messaging method.

But send me your fork. This way i can merge your source and see every change that you did to figure out whats goin on.

@rafaelsetragni
Copy link
Owner

rafaelsetragni commented Nov 25, 2020

In fact, ive merged your changes into my local files, and the messaging firebase method that you sent always complain about the override operation not being possible. In this way, i could not reproduce your error.

But i guess im figuring out whats going on. You said that youre using FirebaseMessaging 7.1.0, but you want to say firebase_messaging: ^7.1.0 instead?

This plugin is not necessary to send push notifications using awesome_notifications. All that you need is inside awesome_notifications plugin and you only need to follow the steps extrictely inside Using Firebase Services (Optional) topic. Is not necessary to use any other plugin or implement any kotlin or java extra script.

Maybe firebase_messaging version is conflicting with my awesome_notifications firebase library, because firebase_messaging is using another library version, that overides mine.

@rafaelsetragni
Copy link
Owner

rafaelsetragni commented Nov 25, 2020

Bingo! That was exactely what happened!

image
image

After update my libraries with pod update, i got your error!

On the newer Firebase version, the firebase team did a lot of changes, including change the method messaging without keep a deprecated version. So, all the sources bellow 7.1.0 will break. And they also changed a lot of things on Android sdk, like making the entire FirebaseInstanceID obsolete.

(iOS) Version 7.1.0 - 11/10/2020
(Android) Cloud Messaging version 21.0.0

You got the newer firebase version after install a firebase plugin or update your pod files. Thats why you have those issues.

All the others awesome_notification developers gonna face the same after update the firebase package. So your change is entirely legit.

The problem that i facing is how to keep both methods working on the same time to not injure the olders projects.

Can you cancel the current pull request to master branch and send the same pull request to update-firebase-sdk branch instead? Theres a lot changes to do on Android side as well.

@derBeukatt
Copy link
Contributor Author

derBeukatt commented Nov 26, 2020

Yeah that is exactly what I was hoping was not happening.
But now that we now the problem it is maybe fixable.
If you need anything else from me, don't hesitate to ask. Thanks for your effort :)

Can you cancel the current pull request to master branch and send the same pull request to update-firebase-sdk branch instead? Theres a lot changes to do on Android side as well.

Consider it done :)

@rafaelsetragni rafaelsetragni added the enhancement New feature or request label Nov 26, 2020
@rafaelsetragni
Copy link
Owner

Ive merged your pull request and included a suport for older versions, as the code bellow. This way, both library versions are compatible with the core code being reusable:

    // For Firebase Messaging versions older than 7.0
    // https://github.com/rafaelsetragni/awesome_notifications/issues/39
    public func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
        
        didReceiveRegistrationToken(messaging, fcmToken: fcmToken)
    }
    
    public func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
        
        if let unwrapped = fcmToken {
            didReceiveRegistrationToken(messaging, fcmToken: unwrapped)
        }
    }
    
    private func didReceiveRegistrationToken(_ messaging: Messaging, fcmToken: String){
        
        print("Firebase registration token: \(fcmToken)")
        let dataDict:[String: String] = ["token": fcmToken]
        NotificationCenter.default.post(name: Notification.Name("FCMToken"), object: nil, userInfo: dataDict)
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants