我建立了一個應用內購買,它工作正常。
然後我創建了一個新的目標c類,並將所有的應用程序購買編碼放在新類中。
好吧,現在我想從我的主視圖控制器調用應用內購買。這怎麼可能?感謝InApp從另一個nsobject購買
viewcontroller.m
- (void)viewDidLoad
{
InAppPurchaseManager *IAPmanager = [[InAppPurchaseManager alloc]init];
if([SKPaymentQueue canMakePayments])
{
//sets payment observer to class.
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
//initializes products array.
products = [[NSMutableArray alloc]init];
[IAPmanager loadStore];
}
else
{
NSLog(@"failed");
}
}
InAppPurchaseManager.m
-(void)loadStore
{
//restarts any purchases if they were interupted last time the was open
[[SKPaymentQueue defaultQueue]addTransactionObserver:self];
//get the product description
ViewController *viewcontroller = [[ViewController alloc]init];
[viewcontroller requestProductData];
}
//request product
-(void)requestProductData
{
NSSet *productIdentifiers = [NSSet setWithObjects:@"com.company.myApp.App1",nil ];
SKProductsRequest *productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers];
productsRequest.delegate = self;
[productsRequest start];
NSLog(@"product request start");
}
它停止這種
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
myproducts = response.products;
for(proUpgradeProduct in myproducts)
{
//debug log.
NSLog(@"Product title: %@" , proUpgradeProduct.localizedTitle);
NSLog(@"Product description: %@" , proUpgradeProduct.localizedDescription);
NSLog(@"Product price: %@" , proUpgradeProduct.price);
NSLog(@"Product id: %@" , proUpgradeProduct.productIdentifier);
}
// invalid purchase
for (NSString *invalidProductId in response.invalidProductIdentifiers)
{
NSLog(@"Invalid product id: %@" , invalidProductId);
}
[[NSNotificationCenter defaultCenter] postNotificationName:kInAppPurchaseManagerProductsFetchedNotification object:self userInfo:nil];
NSLog(@"receive respond");
}
我曾嘗試手動調用所有的方法,如要求產品數據和它的工作great.but,當它來到店裏的東西負責套件一樣 - (空)productsRequest:(SKProductsRequest *)請求didReceiveResponse:(SKProductsResponse *)響應,它在請求產品啓動後從不自行調用 – Albert 2012-02-20 09:44:06