简体   繁体   English

推送通知在杂货店中不起作用

[英]push notification doesn't work in grocer

I am going to send a notification to ios devices by rails backend. 我将通过Rails后端向ios设备发送通知。
I have added grocer gem to Gemfile and then installed it in the project. 我已将杂货店gem添加到Gemfile中,然后将其安装在项目中。

gem 'grocer'

I planed to send a notification in background mode. 我计划在后台模式下发送通知。 So I created resque job and added the grocer logic in app/jobs/notificationsender.rb like this. 因此,我创建了resque作业,并像这样在app / jobs / notificationsender.rb中添加了杂货商逻辑。

def self.perform(language)
    @lang = language

    # Thread.new do
      while true

        begin
            pusher = Grocer.pusher(certificate:  "#{Rails.root}/lib/notification/cer.pem", # required
                       passphrase:  "llvc",                         # optional
                       gateway:     "gateway.sandbox.push.apple.com", # optional
                       port:        2195,                             #optional
                       retries:     3)

        feedback = Grocer.feedback( certificate:  "#{Rails.root}/lib/notification/cer.pem", # required
                                  passphrase:  "llvc",                        
                                  gateway:     "feedback.sandbox.push.apple.com", 
                                  port:        2196,                     
                                  retries:     3)

        note = Grocer::Notification.new(
          device_token: device_token,
          alert: message,
          sound: 'default',
          badge: 0,
          expiry: Time.now + 60*60,
          content_available: true,
          custom: {
            "linkname": linkname,
            "linkurl": linkurl
          }
        )

        feedback.each do |attempt|
          puts "Device #{attempt.device_token} failed at #{attempt.timestamp}"
        end

        pusher.push(note)
        rescue Exception => e
            puts e.class
            puts e
        end

        sleep(5)
      end #while
  end

I got a device token from iphone and sent it to backend. 我从iPhone获得了设备令牌并将其发送到后端。

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    _deviceToken = deviceToken;

    // Store the deviceToken in the current installation and save it to Parse.
    if (currentInstallation == nil) {
        currentInstallation = [[BSGInstallation alloc] init];
    }

    currentInstallation.delegate = self;
    [currentInstallation setDeviceTokenFromData:deviceToken];
    [currentInstallation saveInBackground];
}

I downloaded an apple pushnotification development certificate and generated p12 from it and then created cer.pem file from command line. 我下载了一个苹果pushnotification开发证书,并从中生成了p12,然后从命令行创建了cer.pem文件。
I signed the ios project with app development cer for debug and distribution for release and assigned development provisioning. 我与应用程序开发人员签署了ios项目,以进行调试和分发,以发行和分配开发资源。 Of course I added device identifier to the provisioning correctly. 当然,我将设备标识符正确添加到了配置中。
After building ios, backend, resque job I got a notification after every 5 seconds in iPhone. 在构建ios,后端,reque作业之后,每隔5秒钟我就会在iPhone中收到一条通知。 I installed the app on iPad. 我在iPad上安装了该应用程序。 but the notification doesn't get on the iPad. 但通知不会在iPad上显示。 Of course the id of iphone and ipad were correctly registered. 当然,iphone和ipad的ID已正确注册。 And I confirmed the device token of iphone and ipad was passed on the Grocer::notification.new() 我确认iphone和ipad的设备令牌已在Grocer :: notification.new()上传递
but the notification doesn't work in iPad. 但通知不适用于iPad。 So I reset the server and reinstalled on each devices. 因此,我重置了服务器并在每台设备上重新安装了服务器。 At first I tested for iPad. 起初,我为iPad测试。 the result was the same. 结果是一样的。 And then I move onto iPhone. 然后我转到iPhone。 the system also didn't work in the iphone. 该系统也无法在iPhone中使用。 Before it worked. 在工作之前。 It was very strange. 这很奇怪。
So I want to know the followings. 所以我想知道以下内容。
1) the reason why the notification is received by iphone or ipad. 1)iPhone或iPad收到通知的原因。 I want to know the as many branches as possible so that i can detect the reason quickly by following the steps. 我想知道尽可能多的分支,以便我可以按照以下步骤快速检测原因。
2) Can I check the notification is arrived until APNS? 2)我可以检查通知是否在APNS之前到达吗?
Thanks for reading my long description. 感谢您阅读我的详细描述。

There were no errors in IOS and rails code. IOS和Rails代码中没有错误。
I have took a code signing in ios and created a pem file by the url. 我已经在ios中进行了代码签名,并通过url创建了一个pem文件。
https://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1 https://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1
I got an error when following the github tutorial. 遵循github教程时出现错误。 Thanks. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM