【问题标题】:Push Notifications don't work after deploying Expo app to Apple store's TestFlight将 Expo 应用程序部署到 Apple 商店的 TestFlight 后,推送通知不起作用
【发布时间】:2019-11-17 10:02:33
【问题描述】:

推送通知可以完美地侧载到我的 iOS 手机上。我可以获取令牌并成功将其保存到我的 Google Firestore 数据库中并从中调用它。调用它以发送通知也可以按预期工作。如果我不在应用程序中,我会收到通知。如果我在应用程序中,我的通知侦听器运行良好。

在构建到 iOS 并将独立应用程序部署到 Apple 服务器上的 TestFlight 后,推送通知不再起作用。

这是我的作品。

Adrians-MBP:xxxxx abarthol$ expo build:ios -c
Checking if there is a build in progress...

Removed existing credentials from expo servers
Please enter your Apple Developer Program account credentials. These
credentials are needed to manage certificates, keys and provisioning profiles
in your Apple Developer account.
The password is only used to authenticate with Apple and never stored.
? Apple ID: xxxxx
? Password (for xxxxx): [hidden]
Trying to authenticate with Apple Developer Portal...
Authenticated with Apple Developer Portal successfully!
Only 1 team associated with your account, using Apple Team with ID: xxxxx
We do not have some credentials for you: Apple Distribution Certificate, Apple Push Notifications service key, Apple Provisioning Profile
? How would you like to upload your credentials? Expo handles all credentials, y
ou can still provide overrides
? Will you provide your own Apple Distribution Certificate? Let Expo handle the 
process
✔ Didn't find any previously uploaded Apple Distribution Certificate
? Will you provide your own Apple Push Notifications service key? I want to uplo
ad my own file
Please provide your Apple Push Notifications service key:
? Path to P8 file: ~/Sites/certs/aps.cer
? Key ID: xxxxx
✔ App ID found on Apple Developer Portal.
We're going to generate:
- Apple Distribution Certificate
- Apple Provisioning Profile
✔ Generated Apple Distribution Certificate
✔ Generated Apple Provisioning Profile
Encrypted credentials and saved to the Expo servers
Publishing to channel 'default'...
Building iOS bundle
Building Android bundle
Analyzing assets
Uploading assets
No assets changed, skipped.
Processing asset bundle patterns:
- ~/Sites/Personal/xxxxx/**/*
Uploading JavaScript bundles
Published
Your URL is

https://exp.host/@xxxxx/xxxxx

Checking if this build already exists...

Build started, it may take a few minutes to complete.
You can check the queue length at https://expo.io/turtle-status

You can monitor the build at

 https://expo.io/builds/xxxxx

Waiting for build to complete. You can press Ctrl+C to exit.
✔ Build finished.
Successfully built standalone app: https://expo.io/artifacts/xxxxx

这是我的组件:

  componentDidMount() {
    this.registerForPushNotifications();
  }

  componentWillUnmount() {
    if (!this.subscription) return;
    this.subscription.remove();
  }

  registerForPushNotifications = async () => {
    const PNToken = await this.props.MainStore.getLocal("PNToken");
    if (!PNToken) {
      try {
        const { status } = await Permissions.getAsync(
          Permissions.NOTIFICATIONS
        );
        let finalStatus = status;
        if (status !== "granted") {
          const { status } = await Permissions.askAsync(
            Permissions.NOTIFICATIONS
          );
          finalStatus = status;
          if (finalStatus !== "granted") {
            throw "Notification permission not granted";
          }
          const token = await Notifications.getExpoPushTokenAsync();
          this.props.MainStore.setPNToken(token);
          this.subscription = Notifications.addListener(
            this.handleNotification
          );
        }
      } catch (err) {
        console.warn("Permissions check error: ", err);
      }
    } else {
      this.props.MainStore.setPNToken(PNToken);
      this.subscription = Notifications.addListener(this.handleNotification);
    }
  };

  handleNotification = notification => {
    const store = this.props.NotificationStore;
    const sortedNotifications = sortMessages([
      ...store.state.notifications,
      { ...notification, read: false }
    ]);
    store.setState({
      notifications: sortedNotifications
    });
  };

【问题讨论】:

    标签: react-native apple-push-notifications app-store-connect expo testflight


    【解决方案1】:

    我对 push 最终解决了这个问题感到非常沮丧。 1) 在 Developer portal > Certificates, Identifiers & Profiles > Identifier (of your app) 中启用推送通知 2) 如此处所述创建您的 APNS 密钥文件 https://fluffy.es/p8-push-notification/ 3) 删除现有的配置文件 4) expo build:ios --clear-credentials,上传你的P8文件到expo

    【讨论】:

      【解决方案2】:

      从外观上看,当 Expo 要求新的 P8 格式时,您正在向它提供旧的 APNS 证书。

      您应该能够从 Apple 会员中心生成新的 P8 文件。

      【讨论】:

      • 感谢您的回答。我将其更新为 p8 文件。 AuthKey_XXXXXXXXXX.p8。还是不行。
      • @AdrianBartholomew 您是否使用正确的配置文件和正确的证书?很有可能这是一个临时问题,而不是世博会问题。
      【解决方案3】:

      除了在 expo.io 上拥有正确的“Apple Distribution Certificate”、“Apple Provisioning File”和“Apple Push Key”之外,您还必须拥有正确的设备令牌。 p>

      首先,通过执行expo credentials:manager找到你应用的experienceId 它显示为 经验:@user/slug,包标识符:com.xxx.xxx

      然后按如下方式获取您的令牌

      const token = (
         await Notifications.getExpoPushTokenAsync({
         experienceId: '@user/slug',  // <-- Experience shown above
         })
      ).data;
      console.log('EXPO TOKEN: ', token); // Store this in the backend
      

      将此设备令牌放入expo测试工具(https://expo.io/notifications),看看是否收到通知。

      【讨论】:

        猜你喜欢
        • 2020-04-08
        • 1970-01-01
        • 1970-01-01
        • 2011-07-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-09-16
        • 1970-01-01
        相关资源
        最近更新 更多