Ios 当设备连接到Xcode上时显示alertview的应用程序,否则不会

Ios 当设备连接到Xcode上时显示alertview的应用程序,否则不会,ios,objective-c,xcode,cocoa-touch,web,Ios,Objective C,Xcode,Cocoa Touch,Web,当我在我的设备上启动我的应用程序,同时连接到Xcode时,它工作得非常好。 当我在iPhone上从多任务中删除它后再次启动它时,如果不点击Xcode上的run按钮,它就不能正常工作了 有效的方法是: 在我的viewDidLoad中,我调用[自检索数据] 以下是retrieveData方法:它从web获取数据: 无论何时连接到Xcode,它都能完美工作 但是当我从iPhone启动应用程序时,没有从Xcode界面上的Run按钮启动它,那么locationManager:didUpdateToloca

当我在我的设备上启动我的应用程序,同时连接到Xcode时,它工作得非常好。 当我在iPhone上从多任务中删除它后再次启动它时,如果不点击Xcode上的run按钮,它就不能正常工作了

有效的方法是:

在我的viewDidLoad中,我调用[自检索数据]

以下是retrieveData方法:它从web获取数据: 无论何时连接到Xcode,它都能完美工作

但是当我从iPhone启动应用程序时,没有从Xcode界面上的Run按钮启动它,那么locationManager:didUpdateTolocation方法调用不正确,因为我的应用程序没有正常运行

更多信息,以便更好地理解: 在iPhone模拟器上,弹出窗口显示。从Xcode启动时,在iOS设备上会显示弹出窗口。我不知道为什么当我在没有Xcode和电缆的情况下从iPhone启动时,弹出窗口没有显示,我猜DidUpdateLocation不能正常工作。有什么想法吗

编辑后的评论参考:

#pragma mark - Update Location
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{

    CLLocation *currentLocation = newLocation;
    NSLog(@"didUpdateToLocation: %@", newLocation);

    if (currentLocation != nil) {
        // On affiche la longitude et latitude
        longitudeLabel.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude];
        latitudeLabel.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude];

        CLLocation *userLocation = [[CLLocation alloc] initWithLatitude:currentLocation.coordinate.latitude longitude:currentLocation.coordinate.longitude];

        float distance = [userLocation distanceFromLocation:locDatabase];
        NSLog(@"la distance est de : %f", distance);
        if(distance<0.03)
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Joleju" message:@"Vous entrez dans la zone!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alert show];
        }

        // ---------------------------------------------------------------------------------------------------------------------------

        // Reverse Geocoding
        NSLog(@"Resolving the Address");
        [geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) {
            NSLog(@"Found placemarks: %@, error: %@", placemarks, error);
            if (error == nil && [placemarks count] > 0) {
                placemark = [placemarks lastObject];
                adressLabel.text = [NSString stringWithFormat:@"%@ %@\n%@ %@\n%@\n%@",
                                    placemark.subThoroughfare, placemark.thoroughfare,
                                    placemark.postalCode, placemark.locality,
                                    placemark.administrativeArea,
                                    placemark.country];
            } else {
                NSLog(@"%@", error.debugDescription);
            }
        } ];

    }
}

这是在主/根/主ViewController的viewDidLoad中调用的吗?从AppDelegate启动的一个。如果是这样,则此方法将仅在应用程序首次启动时调用,而不是在应用程序从后台恢复时调用。作为一个实验,将方法调用[self retrieveData]移动到ViewWillDisplay:


更多信息编辑的答案:可能是从后台线程调用了alert view show方法,当您处于调试模式时,该方法仍在工作,但一旦在没有调试器的情况下启动,它就会丢失。UI方法应该始终从主线程调用,因此在[alert show]行上放置一个断点,查看它使用的线程。要修复此问题,请将该行更改为[alert performSelectorOnMainThread:@selectorshow]。我希望这最终能解决您的问题。

您好,谢谢您的回答!是的,它是从我的masterviewcontroller中的viewDidLoad调用的。我知道它从后台恢复时不会被调用。在再次启动之前,我将其从后台删除。因此,即使从viewDidLoad来看,它也应该可以正常工作。我试图从视图中检索数据,但仍然不起作用。这一点都不正常……若你们有什么想法,请和我分享。在retrieveData方法的第一行发出警报,看看它是否被调用。谢谢你们的回答。我刚刚尝试了NSLogs,并从viewDidLoad调用了retrieveData,ViewWillDisplay将出现。现在有一个巨大的变化:我验证了数据是否是从设备上获得的,即使不是从Xcode启动的,并且它是完全下载的!所以问题解决了。但我也明白问题并不在于此。我不知道为什么,当位置匹配时,我的警报没有显示。当我从Xcode启动时,会显示警报。当我不从Xcode启动时,警报不会显示,即使我处理的数据与我启动FRO时的数据完全相同,也不会显示。谢谢你的回答,这里是对你编辑的答案的新评论:在if距离内