好吧,所以我以为我解决了问题,但遇到了另一个问题......
我获取用户的位置,然后使用他们的坐标来查找他们当前所在的邮政编码,但是当我在 block 内运行它时,它只会登录到控制台一次。当我尝试以另一种方法运行该 block 时,它会多次吐出相同的邮政编码。
我的问题是,我该如何制作,以便 block 打印一个邮政编码,并且每次启动 View Controller 时都会执行此操作..?
//user's location
locationManager = [[CLLocationManager alloc] init];
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
[locationManager startUpdatingLocation];
CLGeocoder *fgeo = [[CLGeocoder alloc] init];
[fgeo reverseGeocodeLocation:locationManager.location completionHandler:^(NSArray *placemarks, NSError *error) {
if (!error) {
CLPlacemark *placemark = [placemarks objectAtIndex:0];
zip = placemark.postalCode;
NSLog(@"%@", zip);
//[self jsonRequest];
最佳答案
When I try to run the block in another method it spits out tons of times all with the same zip code.
一旦它进入 If(!error) 并放入一个 return 语句,这应该可以解决问题。
关于ios - 如何让一个 block 运行一次,但每次我启动 viewController 时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18813015/