2016-08-23 1 views
0

코드 도구 응용 프로그램에 https://github.com/katzer/cordova-plugin-background-modehttps://github.com/katzer/cordova-plugin-local-notifications을 설치했습니다.Cordova 응용 프로그램 모니터링 evimings 앱이 죽은 상태 인 동안 Estimote/iBeacon IOS

내 앱이 닫히면 백그라운드에서 비콘을 모니터링하고 비콘이 감지되어 지역에있는 경우 알림을 보내려고합니다.

두 개의 플러그인을 사용하면 사용자가 앱 화면을 종료해도 앱이 정상적으로 작동하지만 사용자가 프로세스를 완전히 죽였을 때 작동하지 않지만 앱이 계속 켜져 있습니다.

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 메서드에서 로그 메시지 나 중단 점을 설정하여 호출되는지 확인합니다.