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

iOS get subscriptions just hangs, never resolves/rejects #1708

Closed
charneykaye opened this issue Jun 1, 2022 · 4 comments
Closed

iOS get subscriptions just hangs, never resolves/rejects #1708

charneykaye opened this issue Jun 1, 2022 · 4 comments

Comments

@charneykaye
Copy link

charneykaye commented Jun 1, 2022

The following component functions nominally under Android. We thought we were cool.

But, the same code on iOS hangs when it tries to get subscriptions. The request doesn't succeed, doesn't fail, doesn't crash. The JS promise is seemingly never resolved or rejected.

Has anyone experienced this? Any ideas on what I should try next?

This is running on my 100% real iPhone logged into my Apple account tethered to my MacBook Pro. There don't appear to be any other issues regarding this phone's ability to make purchases.

Logs

 LOG  [Subscription] Will init connection
 LOG  [Subscription] Did init connection
 LOG  [Subscription] Will clear transaction ios
 LOG  [Subscription] Did clear transaction ios
 LOG  [Subscription] Will get subscription
 ...then nothing, I've waited over 5 minutes...

Component JSX

import React, { Component } from "react";
import { Platform, Text, TouchableOpacity } from "react-native";
import * as Sentry from "@sentry/react-native";
import * as RNIap from "react-native-iap";
import { Subscription, SubscriptionPurchase } from "react-native-iap/src/types";
import { SUBSCRIPTION_ID } from "../env";

class SubscriptionScreen extends Component {
  state = {
    subscription: undefined,
    available: undefined,
  };

  constructor(props) {
    super(props);
  }

  async componentDidMount() {
    try {
      console.log('[Subscription]','Will init connection');
      await RNIap.initConnection();
      console.log('[Subscription]','Did init connection');
      if (Platform.OS === 'ios') {
        console.log('[Subscription]','Will clear transaction ios');
        await RNIap.clearTransactionIOS();
        console.log('[Subscription]','Did clear transaction ios');
      }
      console.log('[Subscription]','Will get subscription');
      const subscription: Subscription = (await RNIap.getSubscriptions([SUBSCRIPTION_ID])).find(s => s.productId === SUBSCRIPTION_ID);
      console.log('[Subscription]','Did get subscription', subscription);
      console.log('[Subscription]','Will get available');
      const available: SubscriptionPurchase = (await RNIap.getAvailablePurchases([SUBSCRIPTION_ID])).find(p => p.productId === SUBSCRIPTION_ID);
      console.log('[Subscription]','Did get available', available);
      this.setState({subscription, available});

    } catch (err) {
      console.error('Failed to get subscriptions!', err.code, err.message);
      Sentry.captureException(err);
    }
  }

  async componentWillUnmount() {
    console.log('[Subscription]','Will close connection');
    await RNIap.endConnection();
    console.log('[Subscription]','Did close connection');
  }

  async purchaseSubscription() {
    try {
      await RNIap.requestSubscription(SUBSCRIPTION_ID);
    } catch (err) {
      console.error('Failed to purchase subscriptions!', err.code, err.message);
      Sentry.captureException(err);
    }
  }

  render() {
    if (this.state.available)
      return (
        <Text>You're a subscriber!</Text>
      )
    else
      return (
        <TouchableOpacity onPress={this.purchaseSubscription} >
          <Text>Subscribe</Text>
        </TouchableOpacity>
      )
  }
}

export default SubscriptionScreen;

Dependencies

"react": "17.0.2",
"react-native": "0.66.3",
"react-native-iap": "^8.0.0-rc.6",

Stack Overflow

Also posted this to https://stackoverflow.com/questions/72466947/react-native-iap-just-hangs-on-ios-trying-to-get-subscriptions-on-ios

@charneykaye
Copy link
Author

Reminiscent of #632

@charneykaye
Copy link
Author

charneykaye commented Jun 1, 2022

Also reminiscent of #984

@charneykaye
Copy link
Author

charneykaye commented Jun 1, 2022

This other iOS issue is still open, potentially nearby #985

@charneykaye
Copy link
Author

Upgrading from react-native-iap@8.0.0-rc.6 to 8.0.10 resolved this issue.

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

No branches or pull requests

1 participant