2011-12-13 64 views
2

這是我第一次與應用程序購買工作,我不知道我做錯了什麼。該SKProductsRequest是可以正常使用,但是當試圖與SIGABRTIAP導致SIGABRT

購買,應用程序崩潰在AppDelegate中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    MKStoreObserver *observer = [[MKStoreObserver alloc] init]; 
    [[SKPaymentQueue defaultQueue] addTransactionObserver:observer]; 
    return YES; 
} 

ViewController.m

- (void)viewDidLoad 
{ 
    if ([SKPaymentQueue canMakePayments]) 
    { 
    [self requestProductData]; 
    } 
    else { 
} 
[super viewDidLoad]; 
} 

- (IBAction)buyButton:(id)sender 
{ 
    SKPayment *payment = [SKPayment paymentWithProduct:kMyFeatureIdentifier]; 
    [[SKPaymentQueue defaultQueue] addPayment:payment]; 

    //When this button is touched the app crashes 
} 

- (void)requestProductData 
{ 
    SKProductsRequest *request = [[SKProductsRequest alloc]  initWithProductIdentifiers:kMyFeatureIdentifier]]; 

    request.delegate = self; 
    [request start]; 
} 

- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response 
{ 
NSArray *myProduct = response.products; 

    if (myProduct.count) { 

    SKProduct *thisProduct = [myProduct objectAtIndex:0]; 


    productTitle.text = [NSString stringWithFormat:@"%@", thisProduct.localizedTitle]; 

    productPrice.text = [NSString stringWithFormat:@"For only $%@", thisProduct.price]; 

    } 
} 

MKStoreObserver.m

- (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 ]; 

      break; 

     default:     

      break; 
    }  
    } 
} 

- (void)completeTransaction: (SKPaymentTransaction *)transaction 
{ 
[[SKPaymentQueue defaultQueue] finishTransaction: transaction]; 
} 

- (void)failedTransaction: (SKPaymentTransaction *)transaction 
{ 
if (transaction.error.code != SKErrorPaymentCancelled) 
{ 
    // Optionally, display an error here. 
} 
[[SKPaymentQueue defaultQueue] finishTransaction: transaction]; 
} 

- (void)restoreTransaction: (SKPaymentTransaction *)transaction 
{ 
    [[SKPaymentQueue defaultQueue] finishTransaction: transaction]; 
} 

當buyButton按下是當應用程序崩潰

這?

GNU GDB 6.3.50-20050815(蘋果版GDB-1708)(週五09月16日六點56分50秒UTC 2011)版權所有2004自由軟件基金會,公司GDB 是免費軟件,由GNU覆蓋通用公共許可證,並歡迎您在某些 條件下更改和/或分發它的副本。輸入「show copying」查看條件。對於GDB,絕對不存在 。請輸入「顯示保修」以瞭解詳情。 這個GDB被配置爲「--host = i386-apple-darwin

--target = arm-apple-darwin」.tty/dev/ttys000 target remote-mobile /tmp/.XcodeGDBRemote-4242-20 Switching to remote-macosx protocol mem 0x1000 0x3fffffff cache mem 0x40000000 0xffffffff none mem 0x00000000 0x0fff none [切換到進程7171線程0x1c03] [切換到 進程7171線程0x1c03] sharedlibrary apply-load-rules全部 2011-12-12 21 :39:11.082 inAppTest [171:707] - [__ NSCFSet productIdentifier]:無法識別的選擇器發送到實例0x134e70 2011-12-12 21:39:11.091 inAppTest [171:707] ***終止應用程序由於 未捕獲異常「NSInvalidArgumentExce ption」,原因: ' - [__ NSCFSet 產品識別]:無法識別的選擇發送到實例0x134e70'

***第一擲調用堆棧:(0x344298bf 0x346791e5 0x3442cacb 0x3442b945 0x34386680 0x3251b2ed 0x2c9d 0x34383435 0x377ed9eb 0x377ed9a7 0x377ed985 0x377ed6f5 0x377ee02d 0x377ec50f 0x377ebf01 0x377d24ed 0x377d1d2d 0x30c04df3 0x343fd553 0x343fd4f5 0x343fc343 0x3437f4dd 0x3437f3a5 0x30c03fcd 0x37800743 0x2a41 0x29d8)終止 叫做拋出異常(GDB)

+0

但什麼的崩潰日誌,我的好男人? – CodaFi

+0

什麼是崩潰日誌? – user975134

回答

0

你在哪裏定義kMyFeatureIdentifier?如果還沒有定義,似乎可能會導致這個錯誤。

0

如果你看看你的崩潰日誌,你會看到這樣一行: - [__ NSCFSet產品識別]:無法識別的選擇發送到實例0x134e70 這意味着某些種類的NSSet中的對象已經被要求爲提供一個值名爲productIdentifier的屬性,它顯然沒有。

問題很可能是paymentWithProduct:方法期望交給SKProduct對象。您似乎正在給它一個NSSet對象。直到它試圖查詢它認爲是其productIdentifier的SKProduct時才注意到它。我可以看到,您在代碼中的其他地方使用了與initWithProductIdentifiers方法相同的常量標識符,該方法需要一套。這可能是你感到困惑的原因。

我建議你把kMyFeatureIdentifier成實際的標識,而不是一組,因爲這正是它的名字所暗示的,然後提供與initWithProductIdentifiers [NSSet中setWithObject:kMyFeatureIdentifier]

相關問題