2015-08-15 6 views
15

Desidero ricevere una notifica quando qualcuno effettua un acquisto in-app nella mia app anziché attendere fino al giorno successivo per verificare se iTunes Connect è in grado di vedere o meno eventuali vendite.C'è un modo per ricevere notifiche quando qualcuno effettua un acquisto in-app?

Qualcuno sa di un modo per farlo? Se no, sarebbe davvero bello!

Grazie

+3

Ovviamente la tua app lo sa. Potresti inviare un messaggio al tuo server. Ma perché? Cosa c'è che non va sapendo una volta al giorno? – rmaddy

+0

Quando dici "invia un messaggio al tuo server", intendi qualcosa come Parse o qualcosa di diverso? Si prega di elaborare. – Creagen

+0

Inoltre, è bello ricevere notifiche quando vendi qualcosa. Un business online riceve email ogni volta che ottengono una vendita. Mi piacerebbe, ma per un'app/vendita in-app. – Creagen

risposta

0

Aggiungi analisi al tuo progetto. Per fare ciò, seguire la Guida rapida: https://parse.com/apps/quickstart#parse_data/mobile/ios/native/existing

Dopo aver impostato l'analisi, aggiungere PFObject *testObject = [PFObject objectWithClassName:@"TestObject"]; testObject[@"foo"] = @"bar"; [testObject saveInBackground]; al codice di transazione completo per ogni acquisto in-app. Per esempio:

- (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]; 
} 

Non dimenticare di aggiungere #import <Parse/Parse.h> alla parte superiore del file header.h.

Non sono sicuro che ci siano altri metodi là fuori in questo modo. È fantastico, quindi divertiti e divertiti a guardare le tue notifiche di acquisto in-app visualizzate in tempo reale!

15

pista StoreKit acquisto Eventi

Quando un acquisto avviene, inviarti un datapoint (Traccia qui ...)

func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) { 
    for transation in transactions { 
     switch transation.transactionState { 

      case .purchased: 
       queue.finishTransaction(transation) 
       // Track here... 

      case .purchasing: break 
      case .restored: break 
      case .deferred: break 
      case .failed: break 
     } 
    } 
} 

biblioteche Leverage

Usa analisi. Sostituisci il commento // Track here... in alto con uno dei blocchi qui sotto. Elenco non esaustivo in ordine alfabetico:

Accengage

NSString *currencyCode = [<SKProduct.priceLocale> 
          objectForKey:NSLocaleCurrencyCode]; 
BMA4SPurchasedItem* item = 
    [BMA4SPurchasedItem itemWithId(t.payment.productIdentifier) 
     label:t.payment.productName 
     category:<product.type> 
     price:@(<SKProduct.price>) 
     quantity:t.payment.quantity 
]; 
[BMA4STracker trackPurchaseWithId:transaction.identifier 
         currency:currencyCode 
          items:@[item]]; 

Branch

NSDictionary *state = @{ 
    @"itemId": @(t.payment.productIdentifier), 
    @"price": <SKProduct.price>, 
    @"itemName": <SKProduct.name>, 
    @"currency":currencyCode }; 
[[Branch getInstance] userCompletedAction:@"purchase" withState:state]; 

Fabric (Crashlytics)

NSString *currencyCode = [<SKProduct.priceLocale> 
          objectForKey:NSLocaleCurrencyCode]; 
[Answers logPurchaseWithPrice:<SKProduct.price> 
        currency:currencyCode 
         success:@YES 
        itemName:<product name> 
        itemType:@"Purchase" 
         itemId:@(t.payment.productIdentifier) 
      customAttributes:@{}]; 

FlightRecorder

FlightRecorder.sharedInstance().trackEventWithCategory(
    "Actions", 
    action: "Purchase", 
    label: "productIdentifier", 
    value: t.payment.productIdentifier) 

Flurry Analytics

let properties = ["productIdentifier":t.payment.productIdentifier] 
Flurry.logEvent("Purchase", withParameters: properties) 

Google Analytics

#import "GAI.h" 
#import "GAIDictionaryBuilder.h" 

id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker]; 
NSString *currencyCode = [<SKProduct.priceLocale> 
          objectForKey:NSLocaleCurrencyCode]; 
[tracker send:[[GAIDictionaryBuilder 
       createItemWithTransactionId:transactionIdentifier 
       name:<product.localizedTitle> 
       sku:t.payment.productIdentifier 
       category:@"Purchase" 
       price:<SKProduct.price> 
       quantity:@(t.payment.quantity) 
       currencyCode:currencyCode] 
       build]]; 

Vedi In-app purchase tracking with Google Analytics iOS SDK.

Heap Analytics

[Heap track:@"Purchase" 
    withProperties:@{@"productIdentifier":@(t.payment.productIdentifier)} 
]; 

MixPanel Analytics (*)

Mixpanel.sharedInstance().track("Purchased", 
           properties: ["productIdentifier":transation.payment.productIdentifier]) 
    properties:@{@"productIdentifier":@(t.payment.productIdentifier)}; 

(*) Fornisce il supporto per la segnalazione WiFi (permette di rinviare tutti i rapporti fino a quando rete WiFi è disponibile, per non utilizzare dati cellulari). Vedi mixpanelWillFlush qui sotto.

Parse.com

NSDictionary *dimensions = 
    @{@"productIdentifier":@(t.payment.productIdentifier)}; 
[PFAnalytics trackEvent:@“Purchase” dimensions:dimensions]; 

Invia una e-mail da un server

POST acquisto a un URL, e hanno a loro volta il server che si invia una mail o altra notifica.

applicazione iOS utilizzando URLSession:

if let url = URL(string: "https://<yoursite>/php/purchase.php") { 
    var request = URLRequest(url: url) 
    request.httpMethod = "POST" 
    request.httpBody = 
     "{\"productIdentifier\":\"\(transaction.payment.productIdentifier)\"}" 
     .data(using: .utf8) 
    request.addValue("application/json", forHTTPHeaderField: "Content-Type") 
    request.addValue("application/json", forHTTPHeaderField: "Accept") 
    let task = URLSession.shared.dataTask(with: request as URLRequest, 
              completionHandler: {_,_,_ in }) 
    task.resume() 
} 

purchase.php e-mail del mittente:

<?php 
try { 
    header('Content-type: application/json'); 
    $to = '[email protected]'; 
    $subject = 'Purchase'; 
    $message = $_POST['productIdentifier']; 
    $headers = "From: " . $to . "\n"; 
    @mail($to, $subject, $message, $headers) 
} catch (Exception $e) {} 
?> 

► Trova questa soluzione su GitHub e ulteriori dettagli su Swift Recipes.

+0

Quindi, stai dicendo, tutto quello che faccio è registrarsi per un account Mixpanel e copiare e incollare quel codice nel mio progetto e inizierò a monitorare gli acquisti in-app? – Creagen

+0

Questo è il concetto: sostituire '// Traccia qui ...' con un pò di codice di tracciamento. – SwiftArchitect

+0

Potrebbe fornire il codice "Invia un messaggio di posta elettronica da un server" in Objc? – Creagen

6

Registrazione tutti gli acquisti IAP nella tabella in Parse.com. È davvero facile trasferire tutti i dati da una ricevuta IAP fino all'analisi. Sto anche facendo abbonamenti non rinnovabili e io uso parse per sincronizzare i dati tra i dispositivi di un utente poiché StoreKit non lo fa automaticamente per gli abbonamenti non rinnovabili.

10

Fabric (ex Crashlytics), oltre ad essere un sistema di arresto di registrazione fantastico (e gratuito), comprende anche un componente chiamato risposte, che tiene traccia le statistiche di utilizzo in tempo reale:

enter image description here

Recentemente, hanno aggiunto la possibilità di aggiungere il tracciamento degli eventi personalizzato, quindi è semplice aggiungere un evento "Prodotto acquistato" all'app. L'aggiunta di Crashlytics alla tua app richiede pochi secondi (e ti guida attraverso il processo) e l'aggiunta di un evento personalizzato come quello richiede una singola riga di codice. Da quel momento in poi, sarai in grado di tenere traccia di tutti i tipi di informazioni sugli acquisti effettuati, il numero di utenti e qualsiasi altro metadata che desideri registrare, il tutto con un ritardo di circa 3 secondi.

Ho utilizzato Crashlytics da anni (in realtà basato su uno StackOverflow question del mio) e NON POSSO raccomandarlo abbastanza. È gratuito, facile e incredibilmente efficace.

+0

@SwiftArchitect Il collegamento è nella risposta, ma [qui vai] (https://get.fabric.io/). Fa tutto parte di un unico framework chiamato Fabric, che include la segnalazione degli arresti anomali, il tracciamento degli eventi e molti altri moduli. Devi solo installare il framework nella tua app (hanno una guida molto facile e intuitiva per l'installazione), e quindi hai accesso a qualsiasi modulo che vuoi utilizzare. – Nerrolken

+1

Uso anche Fabric per tutto quanto sopra menzionato, ma mi chiedevo come monitorare un acquisto con un riacquisto? Attualmente tiene traccia per me e non distingue tra nessuno dei due. –

+0

Tra l'altro le statistiche AWESOME mi piacerebbe arrivare a questo. Quanto ci hai messo? –

Problemi correlati