UIViewControllerの代わりにNSObjectのサブクラスであるシングルトンクラスにCLLocationManagerデリゲートメソッドを配置することはできますか?私は、Idがアプリケーションデリゲートからシングルトンを呼び出し、UIがCLLocationManagerは常にnullです - デリゲートの実装はシングルトンクラスです(UIViewControllerのサブクラスの代わりにNSObjectのサブクラス)
をロードしている間の座標を取得を開始するために好きなように私はlocationcontrollerクラスを持っていると私はそれに
static locationController *sharedLocController = NULL;
+(locationController *) getSharedController
{
if (sharedLocController !=nil)
{
NSLog(@"locationController has already been created.....");
return sharedLocController;
}
@synchronized(self)
{
if (sharedLocController == nil)
{
sharedLocController = [[self alloc] init];
}
}
return sharedLocController;
}
//==============================================================================
+(id)alloc
{
@synchronized([locationController class])
{
NSAssert(sharedLocController == nil, @"Attempted to allocate a second instance of a sharedLocMgr singleton.");
sharedLocController = [super alloc];
return sharedLocController;
}
return nil;
}
//==============================================================================
-(id)init
{
self = [super init];
if(sharedLocController !=nil)
{
if(!self.locMgr)
{
[self initLocationManager];
}
}
return sharedLocController;
}
//==============================================================================
-(void)initLocationManager
{
self.locMgr = [[CLLocationManager alloc] init];
self.locMgr.delegate = self;
self.locMgr.distanceFilter = kCLDistanceFilterNone;
self.locMgr.desiredAccuracy = kCLLocationAccuracyBest;
[self.locMgr startUpdatingLocation];
NSLog(@"location manager object %@", locMgr);
}
を次の初期化コードを持ってこれをやりたいです
問題は、self.locMgrオブジェクトが常にnullであることです。 ありがとう
ありがとう – banditKing