HMS-Core / hms-flutter-plugin

This repo contains all of Flutter HMS plugins.
https://developer.huawei.com/consumer/en/doc/overview/HMS-Core-Plugin?ha_source=hms1
Apache License 2.0
285 stars 142 forks source link

PlatformException(907122045, 6003: certificate fingerprint error, null, null) #316

Closed gidrokolbaska closed 8 months ago

gidrokolbaska commented 1 year ago

Description Hello! We've recently implemented the Huawei Push Kit in order to be able to send notifications to Huawei Devices with no Google Play Services available and it seems to be working just fine in the emulator and for several real users, but for the last 30 days we had ~750 cases with the error from the title.

Here is the stacktrace which Sentry is returning to us:

PlatformException(907122045, 6003: certificate fingerprint error, null, null)

#0 {filename: message_codecs.dart, package: flutter, function: StandardMethodCodec.decodeEnvelope, lineno: 653, abs_path: package:flutter/src/services/message_codecs.dart, in_app: false}
#1 {filename: platform_channel.dart, package: flutter, function: MethodChannel._invokeMethod, lineno: 296, abs_path: package:flutter/src/services/platform_channel.dart, in_app: false}
#2 {abs_path: <asynchronous suspension>}
#3 {filename: push.dart, package: huawei_push, function: Push.turnOnPush, lineno: 24, abs_path: package:huawei_push/src/cli/push.dart, in_app: true}

Everything is configured correctly as per https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/config-agc-0000001050178043, otherwise it wouldn't have worked on emulator

This is how I call the turnOnPush method: image And sometimes, in the onError callback, we receive the following error: type 'PlatformException' is not a subtype of type 'String'. I believe it is somehow connected with the failure of calling the turnOnPush().

And this is how we decide to either launch FCM or HMS Push Kit:

  if (Platform.isAndroid) {
    HmsApiAvailability hmsClient = HmsApiAvailability();
    int hmsStatus = await hmsClient.isHMSAvailable();
    GooglePlayServicesAvailability gmsStatus = await GoogleApiAvailability
        .instance
        .checkGooglePlayServicesAvailability();

    //gms and hms are available
    if (gmsStatus.value == 0 && hmsStatus == 0 ||
        (gmsStatus.value == 0 && hmsStatus != 0)) {
      //Then initialize Firebase Cloud Messaging
      await initFirebaseCloudMessaging();
    }
    //gms is unavailable, but hms is available
    else if ((gmsStatus.value == 1 ||
            gmsStatus.value == 4 ||
            gmsStatus.value == 5 ||
            gmsStatus.value == 6 ||
            gmsStatus.value == 7) &&
        hmsStatus == 0) {
      //Then initialize HMS Push Kit
      await initHMSPushKit();
    }
    //gms is unavailable and we have errors with hms
    //(e.g. old version/unoficial version/ service is installed but unavailable)
    else if ((gmsStatus.value == 1 ||
            gmsStatus.value == 4 ||
            gmsStatus.value == 5 ||
            gmsStatus.value == 6 ||
            gmsStatus.value == 7) &&
        (hmsStatus == 1 ||
            hmsStatus == 2 ||
            hmsStatus == 3 ||
            hmsStatus == 9)) {
// then fire up the getErrorDialog which depends on the hmsStatus code
      hmsClient.getErrorDialog(hmsStatus, 1000, false);
      //and then initialize hms push kit
      await initHMSPushKit();
    }
  } else {
    await initFirebaseCloudMessaging();
  }

Expected behavior Consistent way of enabling push kit. I'm willing to share any other info if you need it

Environment

ozkulbeng commented 12 months ago

Hello @gidrokolbaska A new version of huawei_push has been released. It's suggested to use this version. If the problem still occurs, please do not hesitate to write to us.