我试图在应用购买交易成功后将数据发布到我的数据库。也就是说,当我使用下面的代码时,XCode会抛出错误:
"无法从switch语句跳转到此案例标签"
我该如何解决这个问题?见下面的代码。
的.m
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{
for(SKPaymentTransaction *transaction in transactions){
switch(transaction.transactionState){
case SKPaymentTransactionStatePurchasing: NSLog(@"Transaction state -> Purchasing");
break;
case SKPaymentTransactionStatePurchased:
self.indicatorThree.hidden = YES;
[self.indicatorThree stopAnimating];
self.indicatorTwo.hidden = YES;
[self.indicatorTwo stopAnimating];
self.indicatorThree.hidden = YES;
[self.indicatorThree stopAnimating];
NSMutableDictionary *viewParams3 = [NSMutableDictionary new];
[viewParams3 setValue:@"current_user" forKey:@"view_name"];
[DIOSView viewGet:viewParams3 success:^(AFHTTPRequestOperation *operation, id responseObject) {
self.currentUser = [responseObject mutableCopy];
NSString *pointBalance = self.currentUser[0][@"points balance"];
NSMutableDictionary *userData = [NSMutableDictionary new];
int result = [pointBalance intValue] + [self.pointsPurchase intValue];
NSLog(@"THIS IS THE RESULT POINTS NUMBER %d", result);
NSString *resultPoints = [NSString stringWithFormat:@"%d", result];
NSDictionary *targetPoints = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects: resultPoints, nil] forKeys:[NSArray arrayWithObjects:@"value", nil]];
NSDictionary *finalPoints = [NSDictionary dictionaryWithObject:[NSArray arrayWithObject:targetPoints] forKey:@"und"];
[userData setObject:finalPoints forKey:@"field_points_balance"];
NSLog(@"FINAL POINTS TO POST %@", finalPoints);
NSDictionary *user = [[DIOSSession sharedSession] user];
NSString *uid = user[@"uid"];
[userData setObject:uid forKey:@"uid"];
[DIOSUser
userUpdate:userData
success:^(AFHTTPRequestOperation *op, id response) { /* Handle successful operation here */
NSString *userPoints = user[@"field_points_balance"][@"und"][0][@"value"];
NSLog(@"AFTER SAVE USER POINTS %@", userPoints);
[[NSNotificationCenter defaultCenter] postNotificationName:@"loginComplete" object:nil];
}
failure:^(AFHTTPRequestOperation *op, NSError *err) { /* Handle operation failire here */
NSLog(@"User data failed to update!");
}
];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Failure: %@", [error localizedDescription]);
}];
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
NSLog(@"Transaction state -> Purchased");
break;
case SKPaymentTransactionStateRestored:
NSLog(@"Transaction state -> Restored");
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
if(transaction.error.code == SKErrorPaymentCancelled){
NSLog(@"Transaction state -> Cancelled");
//the user cancelled the payment ;(
}
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
}
}
}
答案 0 :(得分:7)
之前我遇到过同样的问题,只需在你的情况下添加{},你的所有问题都将得到解决。
块定义创建了一个新的作用域,它似乎会干扰编译器正确解释switch语句的能力。
为每个案例标签添加范围分隔符可解决错误。我认为这是因为该块的范围现在明确地是案例范围的子项。
switch (transaction.transactionState) {
case 0:
{
// ...
break;
}
case 1:
{
// ...
break;
}
default:
break;
}