gpt4 book ai didi

iOS不兼容的 block 指针类型问题

转载 作者:技术小花猫 更新时间:2023-10-29 10:22:49 26 4
gpt4 key购买 nike

我在使用 MKStoreKit 的项目中遇到了实现问题.我正在尝试实现具有各种购买选项的 UIAlertView

这是我执行各种操作并调用 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 错误消息:

Incompatible block pointer types sending 'int (^)(NSString *)' to parameter of type 'void (^)(NSString *)'

看来问题是:onComplete:^(NSString* purchasedFeature)onCancelled:^ 但我不知道如何解决这个问题。

最佳答案

您不应该从该 block return TRUE;,因为编译器会假定该 block 返回int,而它应该返回void (因此不兼容的 block 类型)。

...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.
}...

对于第二个 block (onCancelled block ),您可能错过了 NSString* 参数,或者它期望的任何内容。

关于iOS不兼容的 block 指针类型问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10076272/

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