ジオリマインダーがアプリを起動します
-
12-12-2019 - |
質問
私は、地理的釈式学を使用するアプリについて考えています(iOS5で追加されたもの、私が去る/到着したときに場所に私に思い出させる)。しかし、私はこの機能を使用している(実際には場所を使用している)、現在の場所を取得し、それを私のアプリで定義された場所と比較し、それが同じlocであるか否かを確認する必要があります。現在および定義された場所が同じである場合は、アプリを起動してください。
これは可能ですか?
私はあなたが私の目的を理解することを願っています。 事前にありがとう
解決
背景からあなたの場所を監視することができるようになりますが、留意してください、それはあなたのアプリを自動的に起動しません。ローカル通知のようなものを使用して、ユーザーにアプリを開くように促します。しかし、バックグラウンドから自動的に起動することはオプションではありません。少なくともApp Storeの承認オプションではありません。
他のヒント
モニタに領域を設定すると、現在の領域と定義領域のチェックが自動的に行われます。開始するのに最適な場所は、CLLocationManagerDelegate
、特にstartMonitoringForRegion:
のドキュメントを読むことです。あなたがやりたいことは「GeoFencing」と呼ばれます。また、場所の認識を見つけることもできます。ガイド
iPhoneの開発のMの新しいものとして、プログラムでアプリを昼食する方法がわかりませんが、事前定義された場所に到着したトリガーであなたを助けてください。これがコードです。
1:Import CoreLocation.Framework
2:ViewController.hファイルの下のファイル
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface ViewController : UIViewController<CLLocationManagerDelegate>
@end
.
3:InviewController.m
#import "ViewController.h"
@interface ViewController (){
CLLocationManager *locationManager;
CLRegion *mexicoBoundary;
}
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager setDistanceFilter:kCLDistanceFilterNone];
CLLocationCoordinate2D regionCords ;
//19.432608,-99.133208 lat, lon for mexico city
regionCords=CLLocationCoordinate2DMake(19.432608,-99.133208);
//5000 below, is in meters-radius
mexicoBoundary =
[[CLRegion alloc]initCircularRegionWithCenter:regionCords
radius:5000.0
identifier:@"mexico_Day"];
[locationManager startMonitoringForRegion:mexicoBoundary];
}
-(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
NSLog(@"%@: %@", @"region entered", region.identifier);
}
-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
{
NSLog(@"%@: %@", @"region exited", region.identifier);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
.