SORU
24 EKİM 2013, PERŞEMBE


Nasıl bir iOS uygulaması-app satın alma eklemek musunuz?

Nasıl bir iOS uygulaması-app satın alma eklemek musunuz? Ne ayrıntılar vardır ve orada herhangi bir örnek kod. (Soru-Cevap tarzı, bana göre aşağıda yanıtladı)

CEVAP
24 EKİM 2013, PERŞEMBE


En iyi şekilde-app satın almak içinçalışmaböyle büyük mükafat 5 iOS 9 (iOS 8 and 7) aşağıdaki gibidir:

  1. itunes.connect.apple.com gidin ve oturum açın
  2. Tıklayın 8* *sonra istediğiniz app satın alma ekleyin tıklatın
  3. Features Başlığı tıklayın ve soldaki In-App Purchases seçin
  4. Tıklayın orta simgesi
  5. Bu öğretici için, in-app satın alma reklamları kaldırmak için ekleme olacağız, non-consumable seçin. Eğer kullanıcıya fiziksel bir öğe göndermek için gittiğini, consumable seçmelisiniz.
  6. Başvuru adı, ne istersen koy (ama ne olduğunu bildiğinizden emin olun)
  7. Ürün kimliği tld.websitename.appname.referencename koymak için bu en iyi çalışır, örneğin com.jojodmo.blix.removeads kullanabilirsiniz
  8. cleared for sale seçin ve 1 olarak fiyat katmanı seçin (99¢). Tier 2 $1.99 ve tier 3 $2.99 böyle olacaktı. Tam liste tıklayın view pricing matrix kademe kullanmanızı tavsiye ederim genelde en çünkü 1, kimse reklamları kaldırmak için ödeyecek.
  9. add language mavi düğmeye tıklayın ve bilgileri girin. Bu müşteriye gösterilir, bu yüzden onları görmek istemediğin bir şey koymayın
  10. hosting content with Apple seçim içinhayır
  11. İnceleme notları boş bırakabilirsinizŞİMDİLİK.
  12. screenshot for review atlayınŞİMDİLİKbiz geleceğiz atlamak her şey.
  13. ''. Kaydet

Ürün KİMLİĞİ, bu yüzden sabırlı olun iTunesConnect, kayıt için birkaç saat sürebilir.

Şimdi bu yaptığın kurmak in-app satın alma bilgilerini iTunesConnect, gidip içine böyle büyük mükafat proje ve uygulama yöneticisi (mavi sayfa gibi simge üst kısmında nerede yöntemleri ve başlık dosyaları) tıklayın, app altında hedefler (ilk adım olmalıdır) sonra gitmek genel. Alt kısmında, Eğer bunu yapmak istemezsen ... linked frameworks and libraries küçük artı sembolü tıklayın bakın ve 23 ** çerçeve eklemek gerekir, in-app satın alacakDEĞİLçalışma!

Şimdi gerçek kodlama içine almak için gidiyoruz.

.h dosyanıza aşağıdaki kodu ekleyin

BOOL areAdsRemoved;

- (IBAction)purchase;
- (IBAction)restore;
- (IBAction)tapsRemoveAds;

Sonraki, .m dosya içine StoreKit çerçeve alma gibi @interface ilanından sonra SKProductsRequestDelegate SKPaymentTransactionObserver eklemek gerekir:

#import <StoreKit/StoreKit.h>

//put the name of your view controller in place of MyViewController
@interface MyViewController() <SKProductsRequestDelegate, SKPaymentTransactionObserver>

@end

@implementation MyViewController //the name of your view controller (same as above)
  //the code below will be added here
@end

ve şimdi .m dosyanıza aşağıdakileri ekleyin, bu kısmı karışık hale gelir, kod açıklamaları okumanızı öneririm:

//If you have more than one in-app purchase, you can define both of
//of them here. So, for example, you could define both kRemoveAdsProductIdentifier
//and kBuyCurrencyProductIdentifier with their respective product ids
//
//for this example, we will only use one product

#define kRemoveAdsProductIdentifier @"put your product id (the one that we just made in iTunesConnect) in here"

- (IBAction)tapsRemoveAds{
    NSLog(@"User requests to remove ads");

    if([SKPaymentQueue canMakePayments]){
        NSLog(@"User can make payments");

        //If you have more than one in-app purchase, and would like
        //to have the user purchase a different product, simply define 
        //another function and replace kRemoveAdsProductIdentifier with 
        //the identifier for the other product

        SKProductsRequest *productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:kRemoveAdsProductIdentifier]];
        productsRequest.delegate = self;
        [productsRequest start];

    }
    else{
        NSLog(@"User cannot make payments due to parental controls");
        //this is called the user cannot make payments, most likely due to parental controls
    }
}

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{
    SKProduct *validProduct = nil;
    int count = [response.products count];
    if(count > 0){
        validProduct = [response.products objectAtIndex:0];
        NSLog(@"Products Available!");
        [self purchase:validProduct];
    }
    else if(!validProduct){
        NSLog(@"No products available");
        //this is called if your product id is not valid, this shouldn't be called unless that happens.
    }
}

- (IBAction)purchase:(SKProduct *)product{
    SKPayment *payment = [SKPayment paymentWithProduct:product];

    [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
    [[SKPaymentQueue defaultQueue] addPayment:payment];
}

- (IBAction) restore{
    //this is called when the user restores purchases, you should hook this up to a button
    [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}

- (void) paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
{
    NSLog(@"received restored transactions: %i", queue.transactions.count);
    for(SKPaymentTransaction *transaction in queue.transactions){
        if(transaction.transactionState == SKPaymentTransactionStateRestored){
            //called when the user successfully restores a purchase
            NSLog(@"Transaction state -> Restored");

            [self doRemoveAds];
            [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
            break;
        }
    }   
}

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{
    for(SKPaymentTransaction *transaction in transactions){
        switch(transaction.transactionState){
            case SKPaymentTransactionStatePurchasing: NSLog(@"Transaction state -> Purchasing");
                //called when the user is in the process of purchasing, do not add any of your own code here.
                break;
            case SKPaymentTransactionStatePurchased:
            //this is called when the user has successfully purchased the package (Cha-Ching!)
                [self doRemoveAds]; //you can add your code for what you want to happen when the user buys the purchase here, for this tutorial we use removing ads
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                NSLog(@"Transaction state -> Purchased");
                break;
            case SKPaymentTransactionStateRestored:
                NSLog(@"Transaction state -> Restored");
                //add the same code as you did from SKPaymentTransactionStatePurchased here
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                break;
            case SKPaymentTransactionStateFailed:
                //called when the transaction does not finish
                if(transaction.error.code == SKErrorPaymentCancelled){
                    NSLog(@"Transaction state -> Cancelled");
                    //the user cancelled the payment ;(
                }
                [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
                break;
        }
    }
}

Şimdi eklemek istediğiniz kodu için ne olacak ne zaman kullanıcı bitirir işlem için bu öğretici, kullandığımız çıkarma ekler, sen-ecek var Ekle kendi kodu için ne olur banner görünüm yükler.

- (void)doRemoveAds{
    ADBannerView *banner;
    [banner setAlpha:0];
    areAdsRemoved = YES;
    removeAdsButton.hidden = YES;
    removeAdsButton.enabled = NO;
    [[NSUserDefaults standardUserDefaults] setBool:areAdsRemoved forKey:@"areAdsRemoved"];
    //use NSUserDefaults so that you can load whether or not they bought it
    //it would be better to use KeyChain access, or something more secure
    //to store the user data, because NSUserDefaults can be changed.
    //You're average downloader won't be able to change it very easily, but
    //it's still best to use something more secure than NSUserDefaults.
    //For the purpose of this tutorial, though, we're going to use NSUserDefaults
    [[NSUserDefaults standardUserDefaults] synchronize];
}

Eğer uygulama içinde reklam yok eğer, istediğiniz başka bir şey kullanabilirsiniz. Örneğin, arka plan rengini mavi yapabiliriz. Bunu yapmak için kullanmak istiyorum:

- (void)doRemoveAds{
    [self.view setBackgroundColor:[UIColor blueColor]];
    areAdsRemoved = YES
    //set the bool for whether or not they purchased it to YES, you could use your own boolean here, but you would have to declare it in your .h file

    [[NSUserDefaults standardUserDefaults] setBool:areAdsRemoved forKey:@"areAdsRemoved"];
    //use NSUserDefaults so that you can load wether or not they bought it
    [[NSUserDefaults standardUserDefaults] synchronize];
}

Şimdi, bir yerde viewDidLoad yöntem, aşağıdaki kodu eklemek istediğiniz gidiyoruz:

areAdsRemoved = [[NSUserDefaults standardUserDefaults] boolForKey:@"areAdsRemoved"];
[[NSUserDefaults standardUserDefaults] synchronize];
//this will load wether or not they bought the in-app purchase

if(areAdsRemoved){
    [self.view setBackgroundColor:[UIColor blueColor]];
    //if they did buy it, set the background to blue, if your using the code above to set the background to blue, if your removing ads, your going to have to make your own code here
}

Tüm kodlar eklendi, .xib storyboard dosyanıza gidin, ve iki düğme ekleyin, bir söyleyerek, satın alma ve diğer söyleyip geri. Sen o satın alma butonunatapsRemoveAds IBAction kanca, restore IBAction geri yükle düğmesine. restore eylem eğer kullanıcı daha önce uygulama içi satın alma satın olup olmadığını kontrol edin, ve eğer zaten varsa onlara ücretsiz in-app satın verecektir.

Sonraki, Testers yazan yere ** 59 ve sol tıklayın Users and Roles Sandbox Testers Başlığı tıklatın ve sonra sembol ' ı tıklatın. Sadece ilk ve son isim için rastgele şeyler koymak ve e-posta gerçek olmak zorunda değildir - sadece hatırlamak zorunda. Bir şifre hatırlamak gerekir) koymak ve bilgi geri kalanını doldurun. Date of Birth kullanıcı 18 veya daha eski bir tarih yapmanızı tavsiye ederim. App Store TerritoryVARDIRdoğru kır. Sonraki, mevcut iTunes hesabınızdan çıkış yapın (bu öğretici sonra tekrar giriş yapabilirsiniz).

Seni simülatörü üzerinde çalışan deneyin şimdi Eğer iOS cihazınızda uygulamayı çalıştırmak, satın alacakher zamanhata seninGEREKiOS cihazınızda çalıştırın. Uygulama çalışmaya başladığında, satın alma düğmesine dokunun. Itunes hesabınıza oturum açmak için sorulduğunda, biz sadece oluşturduğunuz sınama kullanıcısı olarak oturum açın. Sen 99¢ alımı onaylamak için sorduğunda veya fiyat aşama da sen ne yaparsan,sonrakiBU BİR EKRAN GÖRÜNTÜSÜ ALINbu sizin için kullanacağız 51 ** iTunesConnect üzerinde. Şimdi ödemeyi iptal edin.

Şimdi, 60**,My Apps ^ git git. the app you have the In-app purchase on >In-App Purchases. Ardından uygulama içi satın alma düğmesine tıklayarak uygulama içi satın alma bilgilerini Düzenle altında. Bunu yaptıktan sonra, sadece bilgisayarınıza iPhone aldı ve inceleme için ekran görüntüsü olarak yükleme, inceleme notları, koy o fotoğrafı alınTEST KULLANICIe-posta ve parola. Bu inceleme sürecinde apple yardımcı olacaktır.

Bunu yaptıktan sonra, geri iOS cihazınızı test kullanıcı hesabı olarak oturum hala, uygulama üzerine gidin ve satın alma düğmesine tıklayın. Bu sefer ödeme onaylayınBu hesabınıza HERHANGİ bir para talep edecektir merak etme, test kullanıcı hesapları uygulama içi bedava satın almakÖdemeyi onayladıktan sonra ne kullanıcı ürününüzü satın aldığında aslında olur olur emin olun. Eğer doğru değilse, o zaman doRemoveAds yöntemi ile bir hata olacak bu. değil ise Yine, arka plan değiştirme kullanarak in-app satın alma test etmek için mavi tavsiye ederim, Bu in-app gerçek satın alma olmamalıdır. Eğer herşey yolunda giderse ve iyi. Sadece emin yüklediğinizde yeni bir ikili in-app satın alma eklemek için iTunesConnect olun!


Burada bazı genel hatalar:

Oturum:No Products Available

Bu üç anlama gelebilir:

  • Kodunuzda ın-app satın alma doğru KİMLİK (tanımlayıcı için yukarıdaki kRemoveAdsProductIdentifier kod . koymadın
  • iTunesConnect satılık-app satın alma temizlememişsin
  • In-app satın alma KİMLİĞİ iTunesConnect kayıtlı olması için beklemek yoktu. KİMLİĞİNİ oluşturma birkaç saat bekleyin ve sonra sorunun çözülmesi gerekir.

Eğer ilk kez işe değil mi, sinirli alamadım! PES etme! Bu çalışma, yaklaşık 10 saat doğru kodu arama alamadan beni yaklaşık 5 saat sürdü! Eğer yukarıda tam olarak kodu kullanırsanız, iyi çalışması gerekir. Eğer herhangi bir sorunuz varsa yorum yapmaktan çekinmeyinhiç.

Bu onların iOS için bir uygulama içi satın alma uygulaması eklemek umuduyla tüm yardımcı olur umarım. Şerefe!

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • magnum33563

    magnum33563

    8 NİSAN 2011
  • ŠĩŗĜŕôŵåɭȍҭҭ

    ŠĩŗĜŕô

    29 Kasım 2009
  • tutvid

    tutvid

    19 AĞUSTOS 2006