iOS 本地推送通知没有唤醒设备
iOS Local Push notification not waking up device
我正在开发一个位置感知 iOS 应用程序,当靠近 iBeacon 时它会发出本地通知。我已将地理围栏设置为在设备距离信标约 5 米时触发。
接收通知工作正常,但我只会在解锁设备(触摸 ID 或密码)或使用睡眠唤醒按钮(显示时钟)打开设备时收到通知。
我能做些什么来让通知唤醒设备,使显示屏亮起/振动/播放声音,例如 iMessage 所做的那样。
如果您使用的是 iBeacon,则实际上不需要使用地理围栏。你想要做的是像这样通过 Core Location 使用监控:
CLBeaconRegion *beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:uuid.UUIDString];
[self.locationManager startMonitoringForRegion:beaconRegion];
beaconRegion.notifyEntryStateOnDisplay = YES;
beaconRegion.notifyOnEntry = YES;
beaconRegion.notifyOnExit = YES;
一旦您监控了一个信标区域,当您通过这些核心定位方法遇到该信号时,该应用程序将自动进入和退出:
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region;
- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region;
在这些方法中是您要显示本地通知的地方。
请注意,对于 iOS 版本 7.0 和更高版本,您需要在 info.plist 中输入 NSLocationAlwaysUsageDescription 才能使定位服务与 iBeacons 一起使用。
确保您的应用注册通知设置,同时请求警报和声音类型。自 iOS 8 起,除非用户授予此权限请求,否则您的通知将不会播放声音或唤醒 phone。
有关详细信息,请参阅 here。
if ([[UIApplication sharedApplication]
respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationType types = (UIUserNotificationType) (UIUserNotificationTypeBadge |
UIUserNotificationTypeSound | UIUserNotificationTypeAlert);
UIUserNotificationSettings *mySettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
}
我正在开发一个位置感知 iOS 应用程序,当靠近 iBeacon 时它会发出本地通知。我已将地理围栏设置为在设备距离信标约 5 米时触发。
接收通知工作正常,但我只会在解锁设备(触摸 ID 或密码)或使用睡眠唤醒按钮(显示时钟)打开设备时收到通知。
我能做些什么来让通知唤醒设备,使显示屏亮起/振动/播放声音,例如 iMessage 所做的那样。
如果您使用的是 iBeacon,则实际上不需要使用地理围栏。你想要做的是像这样通过 Core Location 使用监控:
CLBeaconRegion *beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:uuid.UUIDString];
[self.locationManager startMonitoringForRegion:beaconRegion];
beaconRegion.notifyEntryStateOnDisplay = YES;
beaconRegion.notifyOnEntry = YES;
beaconRegion.notifyOnExit = YES;
一旦您监控了一个信标区域,当您通过这些核心定位方法遇到该信号时,该应用程序将自动进入和退出:
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region;
- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region;
在这些方法中是您要显示本地通知的地方。
请注意,对于 iOS 版本 7.0 和更高版本,您需要在 info.plist 中输入 NSLocationAlwaysUsageDescription 才能使定位服务与 iBeacons 一起使用。
确保您的应用注册通知设置,同时请求警报和声音类型。自 iOS 8 起,除非用户授予此权限请求,否则您的通知将不会播放声音或唤醒 phone。
有关详细信息,请参阅 here。
if ([[UIApplication sharedApplication]
respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationType types = (UIUserNotificationType) (UIUserNotificationTypeBadge |
UIUserNotificationTypeSound | UIUserNotificationTypeAlert);
UIUserNotificationSettings *mySettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
}