gpt4 book ai didi

ios - 应用程式内购买授权给您的应用程式编号

转载 作者:行者123 更新时间:2023-12-01 18:58:00 25 4
gpt4 key购买 nike

我真的很困惑,我不知道如何将应用内购买添加到我现有的应用中。在“功能”中,我选择在应用内购买中向我显示仅错误add the in app purchase entitlement to your app id。我在开发中心添加了应用ID,并在itunesconnect中添加了应用内购买。我的捆绑ID是sk.freetech.zatracenacestina.intro,我将应用内购买设置为sk.freetech.zatracenacestina.intro.package,但我不知道该在哪里填写?

谢谢

最佳答案

你可以按照这些教程
1. http://www.raywenderlich.com/21081/introduction-to-in-app-purchases-in-ios-6-tutorial
2. http://www.tutorialspoint.com/ios/ios_in_app_purchase.htm
3. http://code4app.net/ios/In-App-Purchase/4fc85be56803fa4a49000000

创建一个名为IAPHelper的子类的类NSObject

#import <StoreKit/StoreKit.h>


UIKIT_EXTERN NSString *const IAPHelperProductPurchasedNotification;

typedef void (^RequestProductsCompletionHandler)(BOOL success, NSArray * products);
@protocol inAppPurchaseDelegate <NSObject>

@optional
-(void)transactionSucsess:(NSString *)transactionId;
-(void)transactionOnRestore:(NSString *)transactionId;
-(void)transactionOnFail;
@end
@interface IAPHelper : NSObject

@property(nonatomic,readwrite)id<inAppPurchaseDelegate> delegate;

- (id)initWithProductIdentifiers:(NSSet *)productIdentifiers;
- (void)requestProductsWithCompletionHandler:(RequestProductsCompletionHandler)completionHandler;
- (void)buyProduct:(SKProduct *)product;
- (BOOL)productPurchased:(NSString *)productIdentifier;
- (void)restoreCompletedTransactions;



@end

在IAPHelper.m中

导入“IAPHelper.h”
#import <StoreKit/StoreKit.h>

NSString *const IAPHelperProductPurchasedNotification = @"IAPHelperProductPurchasedNotification";


@interface IAPHelper () <SKProductsRequestDelegate, SKPaymentTransactionObserver>
@end


@implementation IAPHelper {
SKProductsRequest * _productsRequest;
RequestProductsCompletionHandler _completionHandler;

NSSet * _productIdentifiers;
NSMutableSet * _purchasedProductIdentifiers;
}


- (id)initWithProductIdentifiers:(NSSet *)productIdentifiers {

if ((self = [super init])) {

// Store product identifiers
_productIdentifiers = productIdentifiers;

// Check for previously purchased products
_purchasedProductIdentifiers = [NSMutableSet set];
for (NSString * productIdentifier in _productIdentifiers) {
BOOL productPurchased = [[NSUserDefaults standardUserDefaults] boolForKey:productIdentifier];
if (productPurchased) {
[_purchasedProductIdentifiers addObject:productIdentifier];
NSLog(@"Previously purchased: %@", productIdentifier);
} else {
NSLog(@"Not purchased: %@", productIdentifier);
}
}

// Add self as transaction observer
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];

}
return self;

}

- (void)requestProductsWithCompletionHandler:(RequestProductsCompletionHandler)completionHandler {

_completionHandler = [completionHandler copy];

_productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:_productIdentifiers];
_productsRequest.delegate = self;
[_productsRequest start];
}

- (BOOL)productPurchased:(NSString *)productIdentifier {
return [_purchasedProductIdentifiers containsObject:productIdentifier];
}

- (void)buyProduct:(SKProduct *)product {

NSLog(@"Buying %@...", product.productIdentifier);

SKPayment * payment = [SKPayment paymentWithProduct:product];
[[SKPaymentQueue defaultQueue] addPayment:payment];

}

#pragma mark - SKProductsRequestDelegate

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response {

NSLog(@"Loaded list of products...");
_productsRequest = nil;

NSArray * skProducts = response.products;
for (SKProduct * skProduct in skProducts) {
NSLog(@"Found product: %@ %@ %0.2f",
skProduct.productIdentifier,
skProduct.localizedTitle,
skProduct.price.floatValue);
}

_completionHandler(YES, skProducts);
_completionHandler = nil;

}

- (void)request:(SKRequest *)request didFailWithError:(NSError *)error {

NSLog(@"Failed to load list of products.");
_productsRequest = nil;

_completionHandler(NO, nil);
_completionHandler = nil;

}

#pragma mark SKPaymentTransactionOBserver

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
for (SKPaymentTransaction * transaction in transactions) {
switch (transaction.transactionState)
{
case SKPaymentTransactionStatePurchased:
[self completeTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
[self failedTransaction:transaction];
break;
case SKPaymentTransactionStateRestored:
[self restoreTransaction:transaction];
default:
break;
}
};
}

- (void)completeTransaction:(SKPaymentTransaction *)transaction {
NSLog(@"completeTransaction...");

[self provideContentForProductIdentifier:transaction.payment.productIdentifier];


[[SKPaymentQueue defaultQueue] finishTransaction:transaction];


if(_delegate)
[_delegate transactionSucsess:transaction.payment.productIdentifier];
}

- (void)restoreTransaction:(SKPaymentTransaction *)transaction {
NSLog(@"restoreTransaction...");

[self provideContentForProductIdentifier:transaction.originalTransaction.payment.productIdentifier];


[[SKPaymentQueue defaultQueue] finishTransaction:transaction];


if(_delegate)
[_delegate transactionOnRestore:transaction.payment.productIdentifier];
}

- (void)failedTransaction:(SKPaymentTransaction *)transaction {

NSLog(@"failedTransaction...");
if (transaction.error.code != SKErrorPaymentCancelled)
{
NSLog(@"Transaction error: %@", transaction.error.localizedDescription);
}

[[SKPaymentQueue defaultQueue] finishTransaction: transaction];

if(_delegate)
[_delegate transactionOnFail];
}

- (void)provideContentForProductIdentifier:(NSString *)productIdentifier {

[_purchasedProductIdentifiers addObject:productIdentifier];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:productIdentifier];
[[NSUserDefaults standardUserDefaults] synchronize];

}

- (void)restoreCompletedTransactions {
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}

@end

创建IAPHelper的类RageIAPHelper子类
#import "IAPHelper.h"

@interface RageIAPHelper : IAPHelper

+ (RageIAPHelper *)sharedInstance;



@end

在RageIAPHelper.m中
#import "RageIAPHelper.h"

@implementation RageIAPHelper

+ (RageIAPHelper *)sharedInstance {
static dispatch_once_t once;
static RageIAPHelper * sharedInstance;
dispatch_once(&once, ^{
NSSet * productIdentifiers = [NSSet setWithObjects:
@"your identifier",@"your identifier",
nil];
sharedInstance = [[self alloc] initWithProductIdentifiers:productIdentifiers];

});
return sharedInstance;
}




@end


[[RageIAPHelper sharedInstance] setDelegate:(id)self];

[[RageIAPHelper sharedInstance] requestProductsWithCompletionHandler:^(BOOL success, NSArray *products) {


if (success) {
totalProduct_Arr =products;
for (SKProduct *s in totalProduct_Arr) {
NSLog(@"product Identifier %@",[s productIdentifier]);
if ([[s productIdentifier]isEqualToString:FULLVERSION]) {
[self.btnFullVersion setEnabled:YES];
}
else if ([[s productIdentifier]isEqualToString:REMOVE_ADS]) {
[self.btnRemoveAd setEnabled:YES];
}
}
}
else{
UIAlertView *alertFail=[[UIAlertView alloc] initWithTitle:@"Product Not Found" message:@"Fails to load product.." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];

[alertFail show];

}
}];

并购买产品
                     [[RageIAPHelper sharedInstance] buyProduct:product];

关于ios - 应用程式内购买授权给您的应用程式编号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25357634/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com