In-App-Käufe Problem

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • In-App-Käufe Problem

    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:

    Quellcode

    1. #import <QuartzCore/QuartzCore.h>
    2. #import <StoreKit/StoreKit.h>
    3. // Premium
    4. SKProductsRequest *productsRequest;
    5. NSArray *validProducts;
    6. UIActivityIndicatorView *activityIndicatorView;
    7. IBOutlet UILabel *productTitleLabel;
    8. IBOutlet UILabel *productDescriptionLabel;
    9. IBOutlet UILabel *productPriceLabel;
    10. IBOutlet UIButton *purchaseButton;
    11. IBOutlet UIButton *premiumtutorials;
    12. // Ende
    13. // Premium
    14. -(void)fetchAvailableProducts;
    15. - (BOOL)canMakePurchases;
    16. - (void)purchaseMyProduct:(SKProduct*)product;
    17. - (IBAction)purchase:(id)sender;
    18. // Ende
    Alles anzeigen


    .h Datei:

    #define kTutorialPointProductID @"meineID"

    Quellcode

    1. - (void)viewDidLoad
    2. {
    3. //
    4. premiumtutorials.enabled = NO;
    5. activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    6. activityIndicatorView.center = self.view.center;
    7. [activityIndicatorView hidesWhenStopped];
    8. [self.view addSubview:activityIndicatorView];
    9. [activityIndicatorView startAnimating];
    10. purchaseButton.hidden = YES;
    11. [self fetchAvailableProducts];
    12. //
    13. }
    14. // Premium
    15. -(void)fetchAvailableProducts{
    16. NSSet *productIdentifiers = [NSSet setWithObjects:kTutorialPointProductID,nil];
    17. productsRequest = [[SKProductsRequest alloc]initWithProductIdentifiers:productIdentifiers];
    18. productsRequest.delegate = self;
    19. [productsRequest start];
    20. }
    21. - (BOOL)canMakePurchases
    22. {
    23. return [SKPaymentQueue canMakePayments];
    24. }
    25. - (void)purchaseMyProduct:(SKProduct*)product{
    26. if ([self canMakePurchases]) {
    27. SKPayment *payment = [SKPayment paymentWithProduct:product];
    28. [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
    29. [[SKPaymentQueue defaultQueue] addPayment:payment];
    30. }
    31. else{
    32. UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"In App Käufe sind deaktiviert in deinem Gerät." message:nil delegate: self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
    33. [alertView show];
    34. }
    35. }
    36. -(IBAction)purchase:(id)sender{
    37. [self purchaseMyProduct:[validProducts objectAtIndex:0]];
    38. purchaseButton.enabled = YES;
    39. }
    40. #pragma mark StoreKit Delegate
    41. -(void)paymentQueue:(SKPaymentQueue *)queue
    42. updatedTransactions:(NSArray *)transactions {
    43. for (SKPaymentTransaction *transaction in transactions) {
    44. switch (transaction.transactionState) {
    45. case SKPaymentTransactionStatePurchasing:
    46. NSLog(@"Purchasing");
    47. break;
    48. case SKPaymentTransactionStatePurchased:
    49. if ([transaction.payment.productIdentifier isEqualToString:kTutorialPointProductID]) {
    50. NSLog(@"Purchased");
    51. UIAlertView *alertView = [[UIAlertView alloc]initWithTitle: @"Level 1 freigeschaltet." message:nil delegate: self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
    52. [alertView show];
    53. premiumtutorials.enabled = YES;
    54. [[NSUserDefaults standardUserDefaults]synchronize];
    55. purchaseButton.hidden = YES;
    56. }
    57. [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
    58. break;
    59. case SKPaymentTransactionStateRestored:
    60. NSLog(@"Restored");
    61. [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
    62. break;
    63. case SKPaymentTransactionStateFailed:
    64. NSLog(@"Purchase failed");
    65. break;
    66. default:
    67. break;
    68. }
    69. }
    70. }
    71. -(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
    72. {
    73. SKProduct *validProduct = nil;
    74. int count = [response.products count];
    75. if (count>0) {
    76. validProducts = response.products;
    77. validProduct = [response.products objectAtIndex:0];
    78. if ([validProduct.productIdentifier
    79. isEqualToString:kTutorialPointProductID]) {
    80. [productTitleLabel setText:[NSString stringWithFormat:
    81. @"%@",validProduct.localizedTitle]];
    82. [productDescriptionLabel setText:[NSString stringWithFormat:
    83. @"%@",validProduct.localizedDescription]];
    84. [productPriceLabel setText:[NSString stringWithFormat:
    85. @"Preis: %@€",validProduct.price]];
    86. }
    87. } else {
    88. UIAlertView *tmp = [[UIAlertView alloc]
    89. initWithTitle:@"Nicht möglich"
    90. message:@"Aktuell nicht möglich"
    91. delegate:self
    92. cancelButtonTitle:nil
    93. otherButtonTitles:@"Ok",nil];
    94. [tmp show];
    95. }
    96. [activityIndicatorView stopAnimating];
    97. purchaseButton.hidden = NO;
    98. }
    99. // ENDE
    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
    Grüße Stefan
  • Quellcode

    1. -(void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
    2. {
    3. SKProduct *validProduct = nil;
    4. int count = [response.products count];
    5. if (count>0) {
    6. _validProducts = response.products;
    7. validProduct = [response.products objectAtIndex:0];
    8. if ([validProduct.productIdentifier
    9. isEqualToString:kTutorialPointProductID]) {
    10. [productTitleLabel setText:[NSString stringWithFormat:
    11. @"%@",validProduct.localizedTitle]];
    12. [productDescriptionLabel setText:[NSString stringWithFormat:
    13. @"%@",validProduct.localizedDescription]];
    14. [productPriceLabel setText:[NSString stringWithFormat:
    15. @"%@€",validProduct.price]];
    16. }
    17. } else {
    18. UIAlertView *tmp = [[UIAlertView alloc]
    19. initWithTitle:@"Nicht möglich"
    20. message:@"Aktuell nicht möglich"
    21. delegate:self
    22. cancelButtonTitle:nil
    23. otherButtonTitles:@"Ok",nil];
    24. [tmp show];
    25. }
    26. purchaseButton.hidden = NO;
    27. }
    Alles anzeigen


    (schreibe gerade noch um)


    Habe den Code von tutorialspoint.com/ios/ios_in_app_purchase.htm
    Was mich wundert, es werden ja meine Labels korrekt ausgefüllt.
    Grüße Stefan

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von stefan_13_ ()