【问题标题】:Detecting iBeacons while iPhone is sleeping, in swift在 iPhone 睡眠时快速检测 iBeacons
【发布时间】:2015-08-22 13:28:15
【问题描述】:

我有一个应用程序可以判断 iBeacon 是否在范围内,有人知道我如何让 iPhone 在 iBeacon 处于范围内时通过推送通知通知用户,即使手机处于睡眠状态?

编辑:我的问题与this question 不同,因为我不知道如何生成推送通知。当应用处于非活动状态时,就更不用说了。

【问题讨论】:

标签: ios swift location ibeacon


【解决方案1】:

通常,信标应用程序使用本地通知而不是远程通知来在信标附近时提醒用户。两者对最终用户来说看起来都是一样的,但是本地通知是从手机上运行的代码启动的,而远程通知是从服务器推送的。您可以在此处了解不同之处:https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction.html

您可以像这样从didEnterRegion 回调发送本地通知:

UILocalNotification *notification = [[UILocalNotification alloc] init];
    notification.alertBody = @"I see a beacon";
    [[UIApplication sharedApplication] presentLocalNotificationNow:notification];

您还需要在didFinishLaunchingWithOptions 方法中请求发送本地通知的权限:

if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]) {
  [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeSound categories:nil]];
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-29
    • 1970-01-01
    • 2012-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多