2016-03-01 53 views
2

我將通過rails backend向ios設備發送通知。
我已將grocer gem添加到Gemfile中,然後將其安裝到項目中。推送通知在商店中不起作用

gem 'grocer' 

我計劃在後臺模式下發送通知。所以我創建了resque作業,並在app/jobs/notificationsender.rb中添加了這樣的grocer邏輯。

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 

我從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]; 
} 

我下載了一個蘋果pushnotification開發證書,並從中產生P12,然後創建命令行cer.pem文件。
我使用應用程序開發cer簽署了ios項目,以進行調試和分發以及分配開發配置。當然,我正確地將設備標識符添加到配置中。
在構建ios,後端,重新調用作業後,我在iPhone中每隔5秒鐘後收到通知。我在iPad上安裝了該應用程序。但通知不會在iPad上顯示。當然,iPhone和iPad的ID是正確註冊的。我確認iPhone和ipad的設備令牌已通過Grocer :: notification.new()
,但通知在iPad中無法使用。所以我重置服務器並重新安裝在每個設備上。起初,我測試了iPad。結果是一樣的。然後我轉移到iPhone上。該系統也沒有在iPhone上工作。在它工作之前。這很奇怪。
所以我想知道以下幾點。
1)iphone或ipad收到通知的原因。我想知道盡可能多的分支,以便我可以按照步驟快速檢測原因。
2)我可以檢查通知是否到達APNS?
感謝您閱讀我的長篇描述。

回答