2017-01-16 1 views
0

iOSで地理情報ベースの通知を実装する方法を探しています。
私は2つの方法を見つけましたが、どちらが最良で違いがあるかわかりませんでした。iOS上のこれらのジオベースの通知方法の違いは何ですか?

1:CLLocationManagerのstartMonitoringの使用 このチュートリアルのように。 https://www.raywenderlich.com/136165/core-location-geofencing-tutorial

2:CLLocationManagerのstartMonitoringおよびUILocalNotificationの領域を使用します。このコードのように

UILocalNotification *localNotif = [[UILocalNotification alloc] init]; 
    if (localNotif == nil) 
     return; 
    localNotif.alertBody = [NSString stringWithFormat:@"Hello!"]; 
    localNotif.soundName = UILocalNotificationDefaultSoundName; 
    localNotif.applicationIconBadgeNumber = 1; 

    CLCircularRegion *region = nil; 

    CLLocationCoordinate2D location = CLLocationCoordinate2DMake(geoPoint.latitude, 
                   geoPoint.longitude); 
    if (CLLocationCoordinate2DIsValid(location)){ 
     region = [[CLCircularRegion alloc] initWithCenter:location 
                radius:50.0 
               identifier:@"region1"]; 

     region.notifyOnExit = NO; 

     localNotif.region = region; 
     localNotif.regionTriggersOnce = YES; 
     [[UIApplication sharedApplication] scheduleLocalNotification:localNotif]; 

    } else { 
     NSDictionary *info = @{NSLocalizedDescriptionKey:@"Invalid coordinate info."}; 
     NSError *error = [NSError errorWithDomain:@"InvalidCLLocationError" 
              code:1999 
             userInfo:info]; 
    } 

答えて

1

アプリは、あなたがUILocalNotificationアプローチを使用する必要があり却下されたときに通知を表示するために。これは、CLLocationManagerのstartMonitoringがアプリが終了した後に動作を停止するためです。基本的には、UILocalNotificationを使用するときにGeofenceを設定しています。

CLLocationManagerのdidEnterRegiondidExitRegionデリゲートメソッドを実装する必要があります。これらの方法では、ローカル通知を設定します。

注意:iOS 10以降、UILocalNotificationは推奨されていません。代わりにUNNotificationRequestを使用してください。

https://developer.apple.com/reference/uikit/uilocalnotification

関連する問題