检查变量是否等于0或1

时间:2019-06-21 18:29:27

标签: ios objective-c

我试图查看我的变量是否等于0或1,但是即使我的else为0并且必须等于0,它也会立即进入我的NSString语句。 / p>

在这种情况下,数据字符串为1。

NSString *udid =[[UIDevice currentDevice] identifierForVendor].UUIDString;

NSURL *targetURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://link.com/pay/test.php?udid=%@", udid]];
NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *dataString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

if([dataString isEqualToString:@"1"]){
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"notpaid"
                                                message:dataString
                                                delegate:self
                                                cancelButtonTitle:@"OK"
                                                otherButtonTitles:nil];

    [alert show];
}else{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"paid"
                                                message:dataString
                                                delegate:self
                                                cancelButtonTitle:@"OK"
                                                otherButtonTitles:nil];

    [alert show];
}

0 个答案:

没有答案