2016-08-23 9 views
0

コードバスアプリケーションにhttps://github.com/katzer/cordova-plugin-background-modehttps://github.com/katzer/cordova-plugin-local-notificationsをインストールしました。Cordovaアプリケーションのモニタリングのエビデンスアプリが死んでいる状態でのEstimote/iBeacon IOS

私は、ビーコンが検出され、地域にいると通知を送信して、バックグラウンドでビーコンを監視しようとしています。

2つのプラグインを使用すると、ユーザーがアプリの画面を終了してもアプリが正常に機能しますが、アプリがまだオンになっていますが、ユーザーがプロセスを完全に終了したときは機能しません。

これはJavascriptのみを使用して行うことができますか、またはAppDelegate.mのコードを変更する必要がありますか?

は、私は次のコードを使用して、これを試してみた:アプリケーションが起動しない

#import "AppDelegate.h" 
#import "MainViewController.h" 
#import <CoreLocation/CoreLocation.h> 

@interface AppDelegate() 
@property (nonatomic, strong) CLLocationManager *locationManager; 
@property(nonatomic, assign) BOOL notifyEntryStateOnDisplay; 
@end 


@implementation AppDelegate 



- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions 
{ 
    self.viewController = [[MainViewController alloc] init]; 

    self.locationManager = [[CLLocationManager alloc] init]; 

    return [super application:application didFinishLaunchingWithOptions:launchOptions]; 
} 

- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region{ 

    UILocalNotification *notification = [[UILocalNotification alloc] init]; 
    NSLog(@"BLUETOOTH"); 
    if(state == CLRegionStateInside) 
    { 
     notification.alertBody = [NSString stringWithFormat:@"You are inside region %@", region.identifier]; 
    } 
    else if(state == CLRegionStateOutside) 
    { 
     notification.alertBody = [NSString stringWithFormat:@"You are outside region %@", region.identifier]; 
    } 
    else 
    { 
     return; 
    } 

    [[UIApplication sharedApplication] presentLocalNotificationNow:notification]; 
} 

@end 

が。バックグラウンドモードとプッシュ通知がオンになるように、xCode [General - > Capabilities]の設定も変更しました。

アプリがバックグラウンドであっても、アプリが殺されると停止しても殺されない場合でも必要なことをアプリは行います。私は、ビーコンが範囲内にあるので、ユーザーがアプリをオンにできるように、アプリがオフラインであるときに通知を送信しようとしています。

答えて

0

いくつかのポイント:

  1. あなたはself.locationManager.delegate=selfを設定し、あなたのAppDelegateがCLLocationManagerDelegateプロトコル、ビーコンが発見されたときに呼ばれるべき、具体的didEnterRegionメソッドを実装する必要があります。

  2. ビーコン監視は、AppDelegateで設定および初期化する必要があります。アプリがフォアグラウンドに切り替わったときに必ずビーコンモニタリングをアクティブにする必要はないため、プラグインに依存することはできません。

  3. テストするときは、AppDelegateのdidEnterRegionメソッドでログメッセージまたはブレークポイントを設定し、呼び出されるかどうかを確認します。

関連する問題