Question

Can't get "receivedUpdatedCustomerInfo" to work (Objective c), please help?

  • 29 September 2022
  • 12 replies
  • 73 views

Badge +3

Hi,  this is our first in app purchase (annual subscription) and the first time using RevenueCat, Overall everything seems to be working except for the following code which is never call  Please help.  Thank you.

 

- (void)purchases:(nonnull RCPurchases *)purchases receivedUpdatedCustomerInfo:(nonnull RCCustomerInfo *)purchaserInfo {

// handle any changes to purchaserInfo 

    NSLog(@"\n\n\n     Purchase Updated INFO: %@", purchaserInfo);

    [self CheckForSubscription];

}


12 replies

Userlevel 3
Badge +8

Did you set the PurchasesDelegate for the SDK?

Badge +3

not to sound dumb, but how do you do that?

Userlevel 3
Badge +8

Asking means you didn’t do that, hopefully this is the reason

    [RCPurchases sharedPurchases].delegate = your object

Please let us know

Badge +3

Thank you for your help.  I set the delegate    [RCPurchases sharedPurchases].delegate = self;   but still nothing. The above code in my post is still not being called.

Userlevel 3
Badge +8

Can you share more code so maybe we can see something?

Badge +3

hopefully this will help.  in my app delegate .h we have...

 

#import <UIKit/UIKit.h>

@import RevenueCat;

@interface AppDelegate : UIResponder <UIApplicationDelegate, RCPurchasesDelegate>{

    

}

@property (strong, nonatomic) UIWindow *window;

@end

 

We call the RevenueCat config in our AppDelegate.m

 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

     

    RCPurchases.logLevel = RCLogLevelDebug;

    

     

       RCConfigurationBuilder *configuration = [RCConfiguration builderWithAPIKey:@"appkey"];

   configuration = [configuration withAppUserID:@""];//@"<app_user_id>"];

       [RCPurchases configureWithConfiguration:[configuration build]];

      

    [RCPurchases sharedPurchases].delegate = self;

    // Override point for customization after application launch.

    return YES;

}

 

This code is also in our AppDelegate.m but is never called.  I also tried putting the below code in our ViewController.m but it is never called either

 

- (void)purchases:(nonnull RCPurchases *)purchases receivedUpdatedPurchaserInfo:(nonnull RCCustomerInfo *)purchaserInfo {

    // handle any changes to purchaserInfo

    

    

    

    NSLog(@"\n\n\n\n                                                  Did receive subscription update!");

    

    NSLog(@"\n\n\n\n");

 

    

    NSLog(@"\n\n\n     WAHOOO      Purchase Updated INFO: %@", purchaserInfo);

   // [self checkSubcribeDate];

}

 

 

 

 

Userlevel 3
Badge +8

Ok, your code looks good.

I saw the following note in one of the SDK samples, it explains the usage of this delegate (look for /purchases-ios/Examples/MagicWeatherSwiftUI/Shared/Sources/Lifecycle/PurchasesDelegateHandler.swift)

/**

     Whenever the `shared` instance of Purchases updates the CustomerInfo cache, this method will be called.

    

     - Note: CustomerInfo is not pushed to each Purchases client, it has to be fetched.

     This delegate method is only called when the SDK updates its cache after an app launch, purchase, restore, or fetch.

     You still need to call `Purchases.shared.customerInfo` to fetch CustomerInfo regularly.

     */

Hope this explains why it is not called as you expect.

Badge +3

Ok, that makes some sense, I initially thought the RevenueCat server sent a notification to the device triggering the receivedUpdatedCustomerInfo into action.  Thank you for explaining this, you have been very helpful.

I do call the getCustomerInfo through out the lifecycle of our app in our ViewController.m  but the receivedUpdatedCustomerInfo never gets called.

 

[[RCPurchases sharedPurchases]  getCustomerInfoWithCompletion:^(RCCustomerInfo * customerInfo, NSError * error) {

             // access latest customerInfo

            NSLog(@"REVCAT Customer INFO: %@",customerInfo);

           NSLog(@"\n\n\n    isActive=%i   Revenue Cat - Expire Date=%@", customerInfo.entitlements[@”entitlement"].isActive , customerInfo.entitlements[@”entitlement"].expirationDate );

        

         BOOL isACTIVE = customerInfo.entitlements[@”entitlement"].isActive;

          if (isACTIVE) {

                    //give user access to subscription code here

          } else {

                  //not subscribed, limit app access code here

      }

}   

 

In spite of calling the getCustomerInfo. the receivedUpdatedCustomerInfo is never called.  Any ideas?

 

I also have one other question, since the receivedUpdatedCustomerInfo does not work how I initially thought.

I am testing our app on an a iPhone and iPad, both devices are using the same AppleID when testing the subscription purchase.  The question I have is when I subscribe on the phone, how can the subscription be detected on the iPad automatically without having to restore purchase on iPad? Is is possible, Or is restoring the purchase the only way?

Userlevel 3
Badge +8

Great!

to answer your question regarding purchasing on two different devices.  I used to store something on the iCloud so that users will automatically get the purchase info without any Restore Purchase button, it was great but it has issues, what if user asks for a refund, Apple doesn’t notify you with this info, so it is better to always check on the device for customer purchases.  Short answer is, always use the Restore Button to protect your assets. Share your thoughts otherwise. 

Badge +3

ok, thank you for your help!

I was just curious about my previous question.  I do call the getCustomerInfo though out our app, but the receivedUpdatedCustomerInfo is still never called?  Any ideas why?

Userlevel 3
Badge +8

Have you tried restore a purchase?  The note says this delegate will be called after restoring a purchase.  Try to restore a purchase on a clean device. 

Badge +3

I’ll try that.  Thank you for all of your help!

Reply