为什么当我通过测试Xcode运行一个程序,然后只在设备上点击图标时会得到不同的结果?

为什么当我通过测试Xcode运行一个程序,然后只在设备上点击图标时会得到不同的结果?,xcode,ios5,Xcode,Ios5,我遇到了一个非常奇怪的问题,因为我在连接到计算机(通过xcode)但在我的设备上测试我的程序时得到了完全不同的结果。只需在不插入xcode的情况下点击图标。(我认为可能是协调问题) 所以我想这两种测试方式之间可能会有区别 很抱歉,我忘记指定了,我以前在两种方式中都会得到相同的结果,但后来我为我的位置管理器创建了一个单例,而不是在每个窗口中创建一个位置管理器对象 以下是我创建标题的方式: #import <Foundation/Foundation.h> #import <UIK

我遇到了一个非常奇怪的问题,因为我在连接到计算机(通过xcode)但在我的设备上测试我的程序时得到了完全不同的结果。只需在不插入xcode的情况下点击图标。(我认为可能是协调问题)

所以我想这两种测试方式之间可能会有区别

很抱歉,我忘记指定了,我以前在两种方式中都会得到相同的结果,但后来我为我的位置管理器创建了一个单例,而不是在每个窗口中创建一个位置管理器对象

以下是我创建标题的方式:

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>

// protocol for sending location updates to another view controller
@protocol LocationManagerDelegate <NSObject>
@required
- (void)locationUpdate:(CLLocation*)location;
@end

@interface LocationManagerSingleton : NSObject <CLLocationManagerDelegate> {

    CLLocationManager* locationManager;
    CLLocation* location;
    //id delegate;
}

@property (nonatomic, retain) CLLocationManager* locationManager;
@property (nonatomic, retain) CLLocation* location;
@property (nonatomic, assign) id <LocationManagerDelegate> delegate;

+ (LocationManagerSingleton*) sharedInstance; // Singleton method

@end

好吧,看来是OpenGL造成了这个问题。我的理论是,由于本地化管理器更新和重画时用于纹理处理的指针变量位于循环内,因此该变量会出错,因为它会在每次运行时重新初始化,但该值不会设置为0,而且由于opengl的指针指向地址,而不是指针,因此它将读取损坏的数据(因为循环可能已经更新了该空间,直到opengl被告知变量的新地址)。但我仍然不知道为什么它在连接到计算机而不是单独运行时工作得很好。

你有什么不同?你是否在运行之间清除了它的多任务?是的,我甚至删除了该程序,这很有趣,因为如果我使用以前的版本,所有程序都运行得很好,该版本不使用单例,而只是cal每个视图中都有一个位置管理器。如果我使用singleton,那么它会产生那些奇怪的结果,所以我认为我的singleton做得不正确。实际定义了什么?在实现文件的第一部分,或者你的意思是我在哪里创建它?我只是做一些类似LocationManagerSingleton*LManager的事情;(在标题中)和MManager=[LotionManagerSingleton sharedInstance];(在实现中)没关系-我快瞎了!你为什么在sharedInstance方法中使用GCD?(你刚才尝试过
@sychronized
?)
#import "LocationManagerSingleton.h"

//static LocationManagerSingleton* sharedCLDelegate = nil;

@implementation LocationManagerSingleton
@synthesize locationManager, location, delegate;

#pragma mark - Singleton Methods -

+ (LocationManagerSingleton*)sharedInstance {

    static LocationManagerSingleton *_sharedInstance;
    if(!_sharedInstance) {
        static dispatch_once_t oncePredicate;
        dispatch_once(&oncePredicate, ^{
            _sharedInstance = [[super allocWithZone:nil] init];
            });
        }

        return _sharedInstance;
}



+ (id)allocWithZone:(NSZone *)zone {    

    return [self sharedInstance];
}


- (id)copyWithZone:(NSZone *)zone {
    return self;    
}

#if (!__has_feature(objc_arc))

- (id)retain {  

    return self;    
}

- (unsigned)retainCount {
    return UINT_MAX;  //denotes an object that cannot be released
}

- (void)release {
    //do nothing
}

- (id)autorelease {

    return self;    
}
#endif

#pragma mark - Custom Methods -

// Add your custom methods here
- (id)init
{
    self = [super init];
    if (self != nil) {
        self.locationManager = [[CLLocationManager alloc] init];
        self.locationManager.delegate = self;
        self.locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
        self.locationManager.distanceFilter = 5;
        self.locationManager.purpose = @"This app uses your location for Augmented Reality";
        [self.locationManager startUpdatingLocation];
        [self.locationManager startUpdatingHeading];

        NSLog(@"LocationManager initialized with accuracy best for Navigation");
        NSLog(@"CUrrent Latitude: %f, Current Longitude: %f",locationManager.location.coordinate.latitude,locationManager.location.coordinate.longitude);
    }
    return self;
}

#pragma mark - CLLocationManagerDelegate Methods -
- (void)locationManager:(CLLocationManager*)manager
    didUpdateToLocation:(CLLocation*)newLocation
           fromLocation:(CLLocation*)oldLocation
{
    /*…some filer method to check if the new location is good …*/
    bool good = YES;
    if (good)
    {
        [self.delegate locationUpdate:newLocation];
    }
    //self.location = newLocation;
    //NSLog(@"Updated: %@",newLocation);    
}


- (void)locationManager:(CLLocationManager*)manager
       didFailWithError:(NSError*)error
{
    /* ... */

}


@end