Question

Paywalls in Objective-c

  • 16 November 2023
  • 3 replies
  • 64 views

Badge +1

I don’t know if paywalls do not work in objective-c or if I’m doing something wrong. Well it currently doesn’t work that way and crashes on initialisation:

RCPaywallViewController *paywallController = [[RCPaywallViewController alloc] init];

[self presentViewController:paywallController animated:YES completion:nil];


3 replies

Userlevel 3
Badge +8

Hi,

It looks like they can be implemented in ObjC, but we don’t have a code example (yet)

In the meantime, you could take this SwiftUI example as a framework and translate it to ObjC (https://www.revenuecat.com/docs/displaying-paywalls)

Badge +1

I made it to work, like this:
 

        [[RCPurchases sharedPurchases] getOfferingsWithCompletion:^(RCOfferings *offerings, NSError *error) {

          if (offerings.current) {

              RCPaywallViewController *paywallController = [[RCPaywallViewController alloc] initWithOffering:offerings.current displayCloseButton:YES];

              [self presentViewController:paywallController animated:YES completion:nil];

 

          } else if (error) {

              [SentrySDK captureError:error];

 

            // optional error handling

              NSLog(@"Offerings error: %@", error);

          }

        }];

But delegate doesn’t work. So I can’t get back info that user purchased subscription.

Badge

I ran in to this yesterday and submitted a PR to expose the delegate variable to Objective-C. 

Reply