Is There A Way To Get Notified When Someone Makes An In-App Purchase?

后端 未结 4 1796
星月不相逢
星月不相逢 2021-02-19 01:22

I\'d like to be notified when someone makes an In-App Purchase in my App rather than wait until the next day to check iTunes Connect to see wether or not I had any sales.

<
4条回答
  •  梦毁少年i
    2021-02-19 02:03

    Add Parse to your project. To do so, follow the Quick Start Guide: https://parse.com/apps/quickstart#parse_data/mobile/ios/native/existing

    Once parse is setup, add PFObject *testObject = [PFObject objectWithClassName:@"TestObject"]; testObject[@"foo"] = @"bar"; [testObject saveInBackground]; to your completeTransaction code for each in-app purchase. For example:

    - (void)completeTransaction:(SKPaymentTransaction *)transaction {
    NSLog(@"completeTransaction...");
    
    [self provideContentForProductIdentifier:transaction.payment.productIdentifier];
    // NEW CODE
    if ([transaction.payment.productIdentifier isEqualToString:@"company.app.iapra"]){
        [[NSUserDefaults standardUserDefaults] setObject: @"No" forKey:KEY];
        [[NSUserDefaults standardUserDefaults] synchronize];
        PFObject *testObject = [PFObject objectWithClassName:@"IAP"];
        testObject[@"TEST"] = @"Purchase Successful";
        [testObject saveInBackground];
    }
    if ([transaction.payment.productIdentifier isEqualToString:@"company.app.iap"]){
        [[NSUserDefaults standardUserDefaults] setObject: @"YES" forKey:KEY];
        [[NSUserDefaults standardUserDefaults] synchronize];
        PFObject *testObject = [PFObject objectWithClassName:@"IAP"];
        testObject[@"TEST"] = @"Purchase Successful";
        [testObject saveInBackground];
    }
    if ([transaction.payment.productIdentifier isEqualToString:@"company.app.iap"]){
        [[NSUserDefaults standardUserDefaults] setObject: @"YES" forKey:KEY];
        [[NSUserDefaults standardUserDefaults] synchronize];
        PFObject *testObject = [PFObject objectWithClassName:@"IAP"];
        testObject[@"TEST"] = @"Purchase Successful";
        [testObject saveInBackground];
    }
    if ([transaction.payment.productIdentifier isEqualToString:@"company.app.iap"]){
        [[NSUserDefaults standardUserDefaults] setObject: @"YES" forKey:KEY];
        [[NSUserDefaults standardUserDefaults] synchronize];
        PFObject *testObject = [PFObject objectWithClassName:@"IAP"];
        testObject[@"TEST"] = @"Purchase Successful";
        [testObject saveInBackground];
    }
    if ([transaction.payment.productIdentifier isEqualToString:@"company.app.iap"]){
        [[NSUserDefaults standardUserDefaults] setObject: @"YES" forKey:KEY];
        [[NSUserDefaults standardUserDefaults] synchronize];
        PFObject *testObject = [PFObject objectWithClassName:@"IAP"];
        testObject[@"TEST"] = @"Purchase Successful";
        [testObject saveInBackground];
    }
    if ([transaction.payment.productIdentifier isEqualToString:@"company.app.iap"]){
        [[NSUserDefaults standardUserDefaults] setObject: @"YES" forKey:KEY];
        [[NSUserDefaults standardUserDefaults] synchronize];
        PFObject *testObject = [PFObject objectWithClassName:@"IAP"];
        testObject[@"TEST"] = @"Purchase Successful";
        [testObject saveInBackground];
    }
    if ([transaction.payment.productIdentifier isEqualToString:@"company.app.iap"]){
        [[NSUserDefaults standardUserDefaults] setObject: @"YES" forKey:KEY];
        [[NSUserDefaults standardUserDefaults] synchronize];
        PFObject *testObject = [PFObject objectWithClassName:@"IAP"];
        testObject[@"TEST"] = @"Purchase Successful";
        [testObject saveInBackground];
    }
    // NEW CODE ^^
    
    [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
    }
    

    Don't forget to add #import to the top of your header.h file.

    I'm not quite sure there are ANY other methods out there like this. It's pretty cool, so enjoy and have fun watching your in-app purchase notifications appear in real time!

提交回复
热议问题