I'am developing a location aware iOS app that sends out local notification when near an iBeacon. I've setup the geofence to trigger when the device is approximately 5 meters away from the beacon.
我正在开发一个位置感知的iOS应用程序,它在iBeacon附近发出本地通知。当设备距离信标大约5米时,我设置地理围栏以触发。
Receiving the notification works fine, but i will only get the notification when i unlock the device (touch id or passcode) or power it on with the sleep wake button (shows the clock).
接收通知工作正常,但我只会在解锁设备(触摸ID或密码)或使用睡眠唤醒按钮(显示时钟)打开电源时收到通知。
Is there anything i can do that the notification wakes up the device so the display lights up / vibrates / plays a sound like for example an iMessage does.
有什么我可以做的通知唤醒设备,所以显示器亮起/振动/播放声音,例如iMessage。
2 个解决方案
#1
1
If you're using iBeacons, you actually don't need to use geofences. What you want to do is use monitoring through Core Location like so:
如果您使用的是iBeacons,实际上您不需要使用地理围栏。您想要做的是通过Core Location进行监控,如下所示:
CLBeaconRegion *beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:uuid.UUIDString];
[self.locationManager startMonitoringForRegion:beaconRegion];
beaconRegion.notifyEntryStateOnDisplay = YES;
beaconRegion.notifyOnEntry = YES;
beaconRegion.notifyOnExit = YES;
Once you are monitoring for a beacon region, the app will automatically enter and exit when you encounter that signal through these core location methods:
监视信标区域后,当您通过这些核心位置方法遇到该信号时,应用程序将自动进入和退出:
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region;
- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region;
Inside these methods is where you want to show your local notification.
在这些方法中,您希望显示本地通知。
Please note that for iOS version 7.0 and newer you need to enter NSLocationAlwaysUsageDescription into your info.plist in order to get location services working with iBeacons.
请注意,对于iOS 7.0及更高版本,您需要在info.plist中输入NSLocationAlwaysUsageDescription,以便获得使用iBeacons的位置服务。
#2
0
Make sure your app registers for notification settings, requesting both Alert and Sound types. As of iOS 8, unless the user grants this permission request, your notifications will not play sounds or wake up the phone.
确保您的应用注册通知设置,同时请求警报和声音类型。从iOS 8开始,除非用户授予此权限请求,否则您的通知将无法播放声音或唤醒手机。
See here for more info.
有关详细信息,请参见此处
if ([[UIApplication sharedApplication]
respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationType types = (UIUserNotificationType) (UIUserNotificationTypeBadge |
UIUserNotificationTypeSound | UIUserNotificationTypeAlert);
UIUserNotificationSettings *mySettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
}
#1
1
If you're using iBeacons, you actually don't need to use geofences. What you want to do is use monitoring through Core Location like so:
如果您使用的是iBeacons,实际上您不需要使用地理围栏。您想要做的是通过Core Location进行监控,如下所示:
CLBeaconRegion *beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:uuid.UUIDString];
[self.locationManager startMonitoringForRegion:beaconRegion];
beaconRegion.notifyEntryStateOnDisplay = YES;
beaconRegion.notifyOnEntry = YES;
beaconRegion.notifyOnExit = YES;
Once you are monitoring for a beacon region, the app will automatically enter and exit when you encounter that signal through these core location methods:
监视信标区域后,当您通过这些核心位置方法遇到该信号时,应用程序将自动进入和退出:
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region;
- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region;
Inside these methods is where you want to show your local notification.
在这些方法中,您希望显示本地通知。
Please note that for iOS version 7.0 and newer you need to enter NSLocationAlwaysUsageDescription into your info.plist in order to get location services working with iBeacons.
请注意,对于iOS 7.0及更高版本,您需要在info.plist中输入NSLocationAlwaysUsageDescription,以便获得使用iBeacons的位置服务。
#2
0
Make sure your app registers for notification settings, requesting both Alert and Sound types. As of iOS 8, unless the user grants this permission request, your notifications will not play sounds or wake up the phone.
确保您的应用注册通知设置,同时请求警报和声音类型。从iOS 8开始,除非用户授予此权限请求,否则您的通知将无法播放声音或唤醒手机。
See here for more info.
有关详细信息,请参见此处
if ([[UIApplication sharedApplication]
respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationType types = (UIUserNotificationType) (UIUserNotificationTypeBadge |
UIUserNotificationTypeSound | UIUserNotificationTypeAlert);
UIUserNotificationSettings *mySettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
}