2013-10-10 18 views
6

次のコードを使用して、iOSアプリケーションの領域を監視しています。私がiOS6でアプリケーションをビルドすると完全に動作します。 iOS7でビルドすると、didEnterRegionはトリガーされません。iOS 7 didEnterRegionがまったく呼び出されない

//作成とiOS

CLLocationCoordinate2D venueCenter = CLLocationCoordinate2DMake([favoriteVenue.venueLat  doubleValue], [favoriteVenue.venueLng doubleValue]); 
CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter:venueCenter radius:REGION_RADIUS identifier:favoriteVenue.venueId]; 

AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate]; 
[appDelegate.locationManager startMonitoringForRegion:[self regionForVenue:favoriteVenue]]; 

// AppDelegate.mにして地域を登録

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region 
{ 
    NSLog(@"Entered region: %@", region.identifier); 
} 

「アプリケーションが位置情報の更新のために登録する」として、私はまた、必要なバックグラウンドモードを設定しています私のplistファイルで。

この機能がiOS7で動作するために欠落していることのアイデアはありますか?

ありがとうございます!

答えて

0

iOS 6と7の両方で動作するものは、領域の監視を開始するように指示するCLLocationManagerDelegateプロトコルに準拠するクラス内にパブリックメソッドを作成することです。たとえば:

//LocationManagerClass.h 

@interface LocationManagerClass : NSObject 

     {... other stuff in the interface file} 

- (void)beginMonitoringRegion:(CLRegion *)region; 

@end 

、その後

//LocationManagerClass.m 

@interface LocationManagerClass() <CLLocationManagerDelegate> 
@end 

@implementation LocationManagerClass 

    {... other important stuff like locationManager:didEnterRegion:} 

- (void)beginMonitoringRegion:(CLRegion *)region 
{ 
    [[CLLocationManager sharedManager] startMonitoringForRegion:region]; 
} 

@end 

にだからあなたの場合には、あなたがサイドノートでは[appDelegate beginMonitoringRegion:region];

を呼ぶだろう、私はアプリのデリゲートであなたの場所の管理コードを入れないで推薦します。技術的にはうまくいくが、一般的にこのようなものには良いデザインパターンではない。上記の例の代わりに、私はそれをおそらくシングルトンになる自身のロケーションマネージャクラスに入れようとします。このブログ記事は、アプリデリゲートにたくさんのものを置かない理由について、いくつかの良いサポートを提供します:http://www.hollance.com/2012/02/dont-abuse-the-app-delegate/

関連する問題