【问题标题】:iBeacons app send a lot notifications in backgroundiBeacons 应用程序在后台发送大量通知
【发布时间】:2015-06-22 07:03:41
【问题描述】:

我编写了一个 iBeacon 应用程序,当用户靠近信标时发送通知。它可以工作,但它会发送很多通知!例如,我的手机附近有一个 iBeacon,它会向我发送大量通知(一分钟内大约 10-15 个通知)

如何每小时只为每个 ibeacon 发送一个警报通知?

我已经准备好向你展示我的代码了,但请告诉我你想看哪部分代码?

这是我的全部 AppDelegate.swift

【问题讨论】:

  • 你应该每秒被叫一次。

标签: ios iphone swift notifications ibeacon


【解决方案1】:

设置一个标志(属性)以保留有警报通知的proximityUUIDCLBeacon,如果它们不在区域内,请将它们删除。

// property
var myUUIDs: NSMutableArray = NSMutableArray()

// didRangeBeacons
if (!myUUIDs.containsObject(nearestBeacon.proximityUUID.UUIDString)) {
    myUUIDs.addObject(nearestBeacon.proximityUUID.UUIDString)
    sendLocalNotificationWithMessage(message, playSound: playSound)  
}

// remove uuid not in beacons
for var i = 0; i < beacons.count; i++ {
    var beacon = beacons[i] as! CLBeacon
    if (!myUUIDs.containsObject(beacon.proximityUUID.UUIDString)) {
        myUUIDs.removeObject(beacon.proximityUUID.UUIDString)
    }
}

【讨论】:

  • 你能解释一下怎么做吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-08-04
  • 1970-01-01
  • 2015-12-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多