在rapns上,我如何知道未注册的GCM设备的令牌,以便我可以从我的数据库中删除它们? [英] On rapns, how can I know the token for unregistered GCM devices so I can remove them from my database?

查看:135
本文介绍了在rapns上,我如何知道未注册的GCM设备的令牌,以便我可以从我的数据库中删除它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用rapns来提供GCM和APNS支持。对于APNS,我知道哪些未注册的设备必须通过on.apns_feedback(rapns.rb)删除:

  on.apns_feedback do |反馈| 
device = AppleDevice.find_by_token(feedback.device_token)
device.destroy if device
end

但是对于GCM,我无法找到一种方法来知道什么设备是未注册的,所以我可以从我的数据库中删除它。



我试过与反射API,但我没有得到on.notification_failed和on.error每当引发一个Rapns :: DeliveryError异常,并且这些方法似乎并没有让我知道未注册的令牌的方式。



我尝试捕捉Rapns :: DeliveryError,但它似乎不起作用。

  messenger = PushMessenger :: Gcm.new 
GoogleDevice.find_in_batches:batch_size => 1000个|设备|
tokens = devices.map(& token)
begin
messenger.deliver(app,token,payload,nil,true)
rescue Rapns :: DeliveryError =>错误
GoogleDevice.destroy_all#只是看看它的工程
结束
结束

PushMessenger:

 模块PushMessenger 
class Gcm
def deliver(app,token,payload, collapse_key = nil,delay_while_idle = nil,expiry = 1.day.to_i)
tokens = * tokens
n = Rapns :: Gcm :: Notification.new
n.app = app
n.registration_ids =令牌
n.collapse_key = collapse_key
n.delay_while_idle = delay_while_idle
n.expiry =过期
n.data =有效负载
n.save!
end
end
end

如何知道令牌对于这些未注册的设备,所以我可以从我的数据库中删除它们?

解决方案

我使用rapns几乎完全相同,所以在这里我的两美分:首先,对于Android设备,您不需要device_token来停用/移除设备(在GCM device_token == registration_id上)。您可以使用Reflection API从 on.notification_failed 回调中获得registration_id。



最后,哪个版本的rapns你正在用吗?现在最后一个版本(3.4.1)的 on.notification_failed 有一个错误,但是3.3.2版本的工作很好,你可以执行如下操作:

  on.notification_failed do | notification | 
device = Device.find_by_token(notification.registration_ids.first)
device.destroy if device
end

希望有所帮助。


I am using rapns to provide GCM and APNS support. For APNS, I know what unregistered device I must delete via on.apns_feedback (rapns.rb):

on.apns_feedback do |feedback|
    device = AppleDevice.find_by_token(feedback.device_token)
    device.destroy if device
end

but for GCM, I can't find a way to know what device is unregistered so I can delete it from my database.

I tried with the reflection API, but I'm not getting on.notification_failed and on.error called whenever a Rapns::DeliveryError exception is raised and those methods doesn't seem to give me a way to know the unregistered tokens.

I tried catching the Rapns::DeliveryError, but it doesn't seem to work.

messenger = PushMessenger::Gcm.new
GoogleDevice.find_in_batches :batch_size => 1000 do |devices|
  tokens = devices.map(&:token)
  begin
    messenger.deliver(app, tokens, payload, nil, true)
  rescue Rapns::DeliveryError => error
    GoogleDevice.destroy_all # Just to see it works
  end
end

PushMessenger:

module PushMessenger
    class Gcm
        def deliver(app, tokens, payload, collapse_key=nil, delay_while_idle=nil, expiry=1.day.to_i)
            tokens = *tokens
            n = Rapns::Gcm::Notification.new
            n.app = app
            n.registration_ids = tokens
            n.collapse_key = collapse_key
            n.delay_while_idle = delay_while_idle
            n.expiry = expiry
            n.data = payload
            n.save!
        end
    end
end

How can I know the token for these unregistered devices so I can remove them from my database?

解决方案

I'm using rapns to do pretty much the same, so here my two cents:

First, for Android devices you don't need the device_token to deactivate/remove the device (On GCM device_token == registration_id). You can get that registration_id from the on.notification_failed callback with the Reflection API.

Last, which version of rapns are you using? Right now the last version (3.4.1) has a bug with on.notification_failed, but version 3.3.2 works just fine and you'll be able to do something like:

on.notification_failed do |notification|
  device = Device.find_by_token(notification.registration_ids.first)
  device.destroy if device
end

Hope that helps.

这篇关于在rapns上,我如何知道未注册的GCM设备的令牌,以便我可以从我的数据库中删除它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆