Open app with iBeacon

前端 未结 2 1516
时光说笑
时光说笑 2021-01-03 13:57

I\'m so excited about the new release of iOs 7.1 with big changes for iBeacon, which is stated in here: http://beekn.net/2014/03/apple-ios-7-1-launches-major-ibeacon-improve

2条回答
  •  走了就别回头了
    2021-01-03 14:44

    iOS does launch your app when enters a iBeacon region even if your app was closed completely. You can verify it by doing following things:

    1. Define locationManager in AppDelegate, and add delegate CLLocationManagerDelegate;
    2. Init locationManager in - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

      self.locationManager = [[CLLocationManager alloc] init];
      self.locationManager.delegate = self;
      
    3. Add methods:

      - (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region {
          if ([region isKindOfClass:[CLBeaconRegion class]]) {
              UILocalNotification *notification = [[UILocalNotification alloc] init];
              notification.alertBody = @"didExitRegion";
              notification.soundName = @"Default";
              [[UIApplication sharedApplication] presentLocalNotificationNow:notification];
          }
      }
      
      
      - (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
          if ([region isKindOfClass:[CLBeaconRegion class]]) {
              UILocalNotification *notification = [[UILocalNotification alloc] init];
              notification.alertBody = @"didEnterRegion";
              notification.soundName = @"Default";
              [[UIApplication sharedApplication] presentLocalNotificationNow:notification];
          }
      }
      

提交回复
热议问题