2012-04-09 62 views
13

我有一個使用MKStoreKit的項目的實施問題。我正在嘗試使用各種購買選項來實施UIAlertViewiOS不兼容的指針類型問題

這裏就是我做各種事情,並調用UIAlertView代碼:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch 
{  
    if(FALSE == payWallFlag) 
    {   
     // Display Alert Dialog 
     UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Subscription Options" 
                  message:@"You do not have an active subscription. Please purchase one of the options below." 
                 delegate:self 
               cancelButtonTitle:@"Cancel" 
               otherButtonTitles:nil]; 

     [message addButtonWithTitle:@"7 Day Subscription $0.99"]; 

     [message show]; 

     return FALSE; 
    } else if(TRUE == payWallFlag) 
    { 
     // Load content 
    } 
} 

這是物理alertView與我試圖調用代碼:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    NSString *title = [alertView buttonTitleAtIndex:buttonIndex]; 

    if([title isEqualToString:@"Cancel"]) 
    { 
     NSLog(@"Cancel Button was selected."); 
    } 
    else if([title isEqualToString:@"7 Day Subscription $0.99"]) 
    { 
     NSLog(@"7 Day Subscription button pressed."); 
     //Buy a 7 day subscription 
     if([SKPaymentQueue canMakePayments]) { 
      [[MKStoreManager sharedManager] buyFeature:kFeatureAId onComplete:^(NSString* purchasedFeature) 
      { 
       NSLog(@"Purchased: %@", purchasedFeature); 
       // Send an alert to the user 
       UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Purchase Successful" 
                   message:@"Thank you. You have successfully purchased a 7 Day Subscription." 
                   delegate:nil 
                 cancelButtonTitle:@"OK" 
                 otherButtonTitles:nil]; 
       [alert autorelease]; 
       [alert show]; 

       // Show the user the content now 
       payWallFlag = TRUE; 
       return TRUE; 
      } 
              onCancelled:^ 
      { 
       // Send an alert to the user 
       UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Purchase Failed" 
                   message:@"Unfortunately you have cancelled your purchase of a 7 Day Subscription. Please try again." 
                   delegate:nil 
                 cancelButtonTitle:@"OK" 
                 otherButtonTitles:nil]; 
       [alert autorelease]; 
       [alert show]; 

       // Block the content again 
       payWallFlag = FALSE; 
      }]; 
     } 
     else 
     { 
      NSLog(@"Parental control enabled"); 
      // Send an alert to the user 
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Purchase Failed" 
                  message:@"Unfortunately Parental Controls are preventing you from purchasing a subscription. Please try again." 
                  delegate:nil 
                cancelButtonTitle:@"OK" 
                otherButtonTitles:nil]; 
      [alert autorelease]; 
      [alert show]; 

      // Block the content again 
      payWallFlag = FALSE; 
     } 
    } 
} 

的問題是我在UIAlertView中收到以下Xcode錯誤消息:

種不兼容的塊指針類型發送 '詮釋(^)(的NSString *)' 到類型的參數 '無效(^)(的NSString *)'

它出現的問題是:onComplete:^(NSString* purchasedFeature)onCancelled:^但我不知道如何解決這個問題。

回答

20

您不應該從該塊中獲取return TRUE;,因爲編譯器假定該塊返回int,而它應該返回void(因此不兼容的塊類型)。

...onComplete:^(NSString* purchasedFeature) { 
    NSLog(@"Purchased: %@", purchasedFeature); 
    // Send an alert to the user 
    UIAlertView *alert = [[UIAlertView alloc] ...]; 
    [alert autorelease]; 
    [alert show]; 

    // Show the user the content now 
    payWallFlag = TRUE; 
    return TRUE; // <--- Remove this line. 
}... 

對於第二塊(onCancelled一個),你可能錯過了NSString*參數,或是別的什麼期望。