APNS会在多少天后将设备标记为不活跃?
创始人
2024-09-09 00:01:35
0

根据 APNS 的文档,APNS 会在设备最后一次连接 APNS 成功后的 30 天后将设备标记为不活跃(inactive)。因此,如果设备在 30 天内与 APNS 成功连接,APNS 就会认为该设备仍然是活跃的(active)。如果设备在 30 天内没有与 APNS 成功连接,则 APNS 会尝试再次连接该设备,如果连接仍然失败,则 APNS 会将该设备标记为不活跃。

以下是一个示例代码,用于检查设备是否被 APNS 标记为不活跃:

let deviceToken = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
guard let apnsExpireDate = apnsExpirationDate(for: deviceToken) else {
    // Device is inactive, handle accordingly
    return
}

let now = Date()
if now > apnsExpireDate {
    // Device is inactive, handle accordingly
} else {
    // Device is still active
}

private func apnsExpirationDate(for deviceToken: String) -> Date? {
    let apnsExpireTimeInterval: TimeInterval = 30 * 24 * 60 * 60 // 30 days in seconds
    let apnsExpireTimeStamp = UInt32(Date().timeIntervalSince1970 - apnsExpireTimeInterval)
    let apnsExpireByteValue = withUnsafeBytes(of: apnsExpireTimeStamp) { Data($0) }.suffix(4)
    let deviceTokenData = Data(hexEncoded: deviceToken)
    var apnsDeviceToken = Data(repeating: 0, count: 32)
    apnsDeviceToken.append(deviceTokenData)
    apnsDeviceToken.append(apnsExpireByteValue)
    return Date(timeIntervalSince1970: TimeInterval(bigEndian: apnsExpireTimeStamp))
}

extension Data {
    init?(hexEncoded string: S) {
        guard let regex = try? NSRegularExpression(pattern: "^[0-9a-f]{2}$", options: .caseInsensitive) else {
            return nil
        }
        guard regex.matches(in: String(string), options: [], range: NSRange(location: 0, length: string.utf16.count)).count == string.utf16.count / 2 else {
            return nil
        }
        self.init(capacity: string.utf16.count / 2)
        var iterator = string.utf16.makeIterator()
        while let high = iterator.next(), let low = iterator.next() {

相关内容

热门资讯

安装apache-beam==... 出现此错误可能是因为用户的Python版本太低,而apache-beam==2.34.0需要更高的P...
避免在粘贴双引号时向VS 20... 在粘贴双引号时向VS 2022添加反斜杠的问题通常是由于编辑器的自动转义功能引起的。为了避免这个问题...
Android Recycle... 要在Android RecyclerView中实现滑动卡片效果,可以按照以下步骤进行操作:首先,在项...
omi系统和安卓系统哪个好,揭... OMI系统和安卓系统哪个好?这个问题就像是在问“苹果和橘子哪个更甜”,每个人都有自己的答案。今天,我...
原生ios和安卓系统,原生对比... 亲爱的读者们,你是否曾好奇过,为什么你的iPhone和安卓手机在操作体验上有着天壤之别?今天,就让我...
Android - 无法确定任... 这个错误通常发生在Android项目中,表示编译Debug版本的Java代码时出现了依赖关系问题。下...
Android - NDK 预... 在Android NDK的构建过程中,LOCAL_SRC_FILES只能包含一个项目。如果需要在ND...
Akka生成Actor问题 在Akka框架中,可以使用ActorSystem对象生成Actor。但是,当我们在Actor类中尝试...
Agora-RTC-React... 出现这个错误原因是因为在 React 组件中使用,import AgoraRTC from “ago...
Alertmanager在pr... 首先,在Prometheus配置文件中,确保Alertmanager URL已正确配置。例如:ale...