Hallo ich möchte gerne In-App-Käufe integrieren, leider hängt sich meine App auf.
Folgendes habe ich gemacht:
• In-App Purchase in Xcode 5 aktiviert
• StoreKit und QuarzCore Framework hinzugefügt
• Profisional Profil ist auch für in-App-Käufe zugelassen.
.h Ausschnitt:
Alles anzeigen
.h Datei:
#define kTutorialPointProductID @"meineID"
Alles anzeigen
Die ID der In-App-Kaufes ist richtig
Meine App stürzt bei dem Klick auf kaufen komplett ab.
Hätte jemand eine Lösung?
Ich wäre sehr dankbar
Beste Grüße
Folgendes habe ich gemacht:
• In-App Purchase in Xcode 5 aktiviert
• StoreKit und QuarzCore Framework hinzugefügt
• Profisional Profil ist auch für in-App-Käufe zugelassen.
.h Ausschnitt:
Quellcode
- #import <QuartzCore/QuartzCore.h>
- #import <StoreKit/StoreKit.h>
- // Premium
- SKProductsRequest *productsRequest;
- NSArray *validProducts;
- UIActivityIndicatorView *activityIndicatorView;
- IBOutlet UILabel *productTitleLabel;
- IBOutlet UILabel *productDescriptionLabel;
- IBOutlet UILabel *productPriceLabel;
- IBOutlet UIButton *purchaseButton;
- IBOutlet UIButton *premiumtutorials;
- // Ende
- // Premium
- -(void)fetchAvailableProducts;
- - (BOOL)canMakePurchases;
- - (void)purchaseMyProduct:(SKProduct*)product;
- - (IBAction)purchase:(id)sender;
- // Ende
.h Datei:
#define kTutorialPointProductID @"meineID"
Quellcode
- - (void)viewDidLoad
- {
- //
- premiumtutorials.enabled = NO;
- activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
- activityIndicatorView.center = self.view.center;
- [activityIndicatorView hidesWhenStopped];
- [self.view addSubview:activityIndicatorView];
- [activityIndicatorView startAnimating];
- purchaseButton.hidden = YES;
- [self fetchAvailableProducts];
- //
- }
- // Premium
- -(void)fetchAvailableProducts{
- NSSet *productIdentifiers = [NSSet setWithObjects:kTutorialPointProductID,nil];
- productsRequest = [[SKProductsRequest alloc]initWithProductIdentifiers:productIdentifiers];
- productsRequest.delegate = self;
- [productsRequest start];
- }
- - (BOOL)canMakePurchases
- {
- return [SKPaymentQueue canMakePayments];
- }
- - (void)purchaseMyProduct:(SKProduct*)product{
- if ([self canMakePurchases]) {
- SKPayment *payment = [SKPayment paymentWithProduct:product];
- [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
- [[SKPaymentQueue defaultQueue] addPayment:payment];
- }
- else{
- UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"In App Käufe sind deaktiviert in deinem Gerät." message:nil delegate: self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
- [alertView show];
- }
- }
- -(IBAction)purchase:(id)sender{
- [self purchaseMyProduct:[validProducts objectAtIndex:0]];
- purchaseButton.enabled = YES;
- }
- #pragma mark StoreKit Delegate
- -(void)paymentQueue:(SKPaymentQueue *)queue
- updatedTransactions:(NSArray *)transactions {
- for (SKPaymentTransaction *transaction in transactions) {
- switch (transaction.transactionState) {
- case SKPaymentTransactionStatePurchasing:
- NSLog(@"Purchasing");
- break;
- case SKPaymentTransactionStatePurchased:
- if ([transaction.payment.productIdentifier isEqualToString:kTutorialPointProductID]) {
- NSLog(@"Purchased");
- UIAlertView *alertView = [[UIAlertView alloc]initWithTitle: @"Level 1 freigeschaltet." message:nil delegate: self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
- [alertView show];
- premiumtutorials.enabled = YES;
- [[NSUserDefaults standardUserDefaults]synchronize];
- purchaseButton.hidden = YES;
- }
- [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
- break;
- case SKPaymentTransactionStateRestored:
- NSLog(@"Restored");
- [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
- break;
- case SKPaymentTransactionStateFailed:
- NSLog(@"Purchase failed");
- break;
- default:
- break;
- }
- }
- }
- -(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
- {
- SKProduct *validProduct = nil;
- int count = [response.products count];
- if (count>0) {
- validProducts = response.products;
- validProduct = [response.products objectAtIndex:0];
- if ([validProduct.productIdentifier
- isEqualToString:kTutorialPointProductID]) {
- [productTitleLabel setText:[NSString stringWithFormat:
- @"%@",validProduct.localizedTitle]];
- [productDescriptionLabel setText:[NSString stringWithFormat:
- @"%@",validProduct.localizedDescription]];
- [productPriceLabel setText:[NSString stringWithFormat:
- @"Preis: %@€",validProduct.price]];
- }
- } else {
- UIAlertView *tmp = [[UIAlertView alloc]
- initWithTitle:@"Nicht möglich"
- message:@"Aktuell nicht möglich"
- delegate:self
- cancelButtonTitle:nil
- otherButtonTitles:@"Ok",nil];
- [tmp show];
- }
- [activityIndicatorView stopAnimating];
- purchaseButton.hidden = NO;
- }
- // ENDE
Die ID der In-App-Kaufes ist richtig
Meine App stürzt bei dem Klick auf kaufen komplett ab.
Hätte jemand eine Lösung?
Ich wäre sehr dankbar
Beste Grüße
Grüße Stefan