2017-07-12 7 views
1

PushKitを実装しました。一部のデバイスでプッシュキットトークンが取得されないiOS

1)​​

2)https://stackoverflow.com/a/28562124

私はdidUpdatePushCredentialsデバイストークンを取得することができる午前:私はこれらの手順に従ってきました。私は同じcerificatesを使用して、すべてのデバイスのために構築しています> iPhone6とiPhone7

- に動作していない> iPhone 5S、iPhone6プラス

didUpdatePushCredentialsを - がで働きます。正確な問題を知らない。 誰かがこの種の問題に直面した場合は、回避策を教えてください。

私のコードと証明書のリンク

コード - >https://www.dropbox.com/sh/x2615t7xn8mavs3/AADbX5nBuF5_08YNPX8wI59ga?dl=0

CER - PushKitの場合>https://www.dropbox.com/sh/70l4htj1c46emog/AABxBalaoN1JP22dQp8-mNXGa?dl=0

Solution -----> I have changed Bundle identifier And create New certificate with New BundleId. 
+0

これらの端末でインターネット接続をチェックしましたか? – D4ttatraya

+0

プロジェクト機能でvoip設定のバックグラウンドモードを有効にし、デバイスのアプリプッシュ通知設定もチェックしてください。設定を有効にする必要があります。 – Rivendell

答えて

0

正しく統合されていると、すべてのデバイスで動作するはずです。デバイスに固有のものは何も変更されていません。

ステップを確認することができます。

スウィフト

import UIKit 
import PushKit 

@UIApplicationMain 
class AppDelegate: UIResponder, UIApplicationDelegate,PKPushRegistryDelegate { 

    var window: UIWindow? 

    var isUserHasLoggedInWithApp: Bool = true 
    var checkForIncomingCall: Bool = true 
    var userIsHolding: Bool = true 

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 


     if #available(iOS 8.0, *){ 


      let viewAccept = UIMutableUserNotificationAction() 
      viewAccept.identifier = "VIEW_ACCEPT" 
      viewAccept.title = "Accept" 
      viewAccept.activationMode = .Foreground 
      viewAccept.destructive = false 
      viewAccept.authenticationRequired = false 

      let viewDecline = UIMutableUserNotificationAction() 
      viewDecline.identifier = "VIEW_DECLINE" 
      viewDecline.title = "Decline" 
      viewDecline.activationMode = .Background 
      viewDecline.destructive = true 
      viewDecline.authenticationRequired = false 

      let INCOMINGCALL_CATEGORY = UIMutableUserNotificationCategory() 
      INCOMINGCALL_CATEGORY.identifier = "INCOMINGCALL_CATEGORY" 
      INCOMINGCALL_CATEGORY.setActions([viewAccept,viewDecline], forContext: .Default) 

      if application.respondsToSelector("isRegisteredForRemoteNotifications") 
      { 
       let categories = NSSet(array: [INCOMINGCALL_CATEGORY]) 
       let types:UIUserNotificationType = ([.Alert, .Sound, .Badge]) 

       let settings:UIUserNotificationSettings = UIUserNotificationSettings(forTypes: types, categories: categories as? Set<UIUserNotificationCategory>) 

       application.registerUserNotificationSettings(settings) 
       application.registerForRemoteNotifications() 
      } 

     } 
     else{ 
      let types: UIRemoteNotificationType = [.Alert, .Badge, .Sound] 
      application.registerForRemoteNotificationTypes(types) 
     } 


     self.PushKitRegistration() 

    return true 
    } 
    //MARK: - PushKitRegistration 

    func PushKitRegistration() 
    { 

     let mainQueue = dispatch_get_main_queue() 
     // Create a push registry object 
     if #available(iOS 8.0, *) { 

     let voipRegistry: PKPushRegistry = PKPushRegistry(queue: mainQueue) 

     // Set the registry's delegate to self 

     voipRegistry.delegate = self 

     // Set the push type to VoIP 

     voipRegistry.desiredPushTypes = [PKPushTypeVoIP] 

     } else { 
     // Fallback on earlier versions 
     } 


    } 


    @available(iOS 8.0, *) 
    func pushRegistry(registry: PKPushRegistry!, didUpdatePushCredentials credentials: PKPushCredentials!, forType type: String!) { 
     // Register VoIP push token (a property of PKPushCredentials) with server 

     let hexString : String = UnsafeBufferPointer<UInt8>(start: UnsafePointer(credentials.token.bytes), 
     count: credentials.token.length).map { String(format: "%02x", $0) }.joinWithSeparator("") 

     print(hexString) 


    } 


    @available(iOS 8.0, *) 
    func pushRegistry(registry: PKPushRegistry!, didReceiveIncomingPushWithPayload payload: PKPushPayload!, forType type: String!) { 

     // Process the received push 

     // Below process is specific to schedule local notification once pushkit payload received 

     var arrTemp = [NSObject : AnyObject]() 
     arrTemp = payload.dictionaryPayload 

     let dict : Dictionary <String, AnyObject> = arrTemp["aps"] as! Dictionary<String, AnyObject> 


     if isUserHasLoggedInWithApp // Check this flag then only proceed 
     { 

      if UIApplication.sharedApplication().applicationState == UIApplicationState.Background || UIApplication.sharedApplication().applicationState == UIApplicationState.Inactive 
      { 

       if checkForIncomingCall // Check this flag to know incoming call or something else 
       { 

        var strTitle : String = dict["alertTitle"] as? String ?? "" 
        let strBody : String = dict["alertBody"] as? String ?? "" 
        strTitle = strTitle + "\n" + strBody 

        let notificationIncomingCall = UILocalNotification() 

        notificationIncomingCall.fireDate = NSDate(timeIntervalSinceNow: 1) 
        notificationIncomingCall.alertBody = strTitle 
        notificationIncomingCall.alertAction = "Open" 
        notificationIncomingCall.soundName = "SoundFile.mp3" 
        notificationIncomingCall.category = dict["category"] as? String ?? "" 

        //"As per payload you receive" 
        notificationIncomingCall.userInfo = ["key1": "Value1" ,"key2": "Value2" ] 


        UIApplication.sharedApplication().scheduleLocalNotification(notificationIncomingCall) 

       } 
       else 
       { 
        // something else 
       } 

      } 
     } 


    } 

    //MARK: - Local Notification Methods 

    func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification){ 

     // Your interactive local notification events will be called at this place 

    } 


} 

オブジェクティブC

#import <UIKit/UIKit.h> 
#import <PushKit/PushKit.h> 

@interface AppDelegate : UIResponder <UIApplicationDelegate,PKPushRegistryDelegate> 
{ 
    PKPushRegistry *pushRegistry; 
} 

@property (strong, nonatomic) UIWindow *window; 

@end 

#import "AppDelegate.h" 

@interface AppDelegate() 

@end 

@implementation AppDelegate 


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 


    pushRegistry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()]; 
    pushRegistry.delegate = self; 
    pushRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP]; 

    return YES; 
} 

#define PushKit Delegate Methods 

- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type{ 
    if([credentials.token length] == 0) { 
     NSLog(@"voip token NULL"); 
     return; 
    } 

    NSLog(@"PushCredentials: %@", credentials.token); 
} 

- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type 
{ 
    NSLog(@"didReceiveIncomingPushWithPayload"); 
} 

https://github.com/hasyapanchasara/PushKit_SilentPushNotification

更新答え

https://drive.google.com/file/d/0B7ooURy3zGWKYW5PZE1aN2pObW8/view?usp=sharing

更新答え

は、以下のオプションを撮影いくつかの問題です。

(1)変更コム識別子と再び

を試す(2)私は推測するアプリのdelegeateに

をpuhkitコードを保ち、あなたのバンドル識別子を変更して再試行することができ、それがすべてで作業しなければならデバイス。

+0

あなたのプロジェクトを解凍し、VOIPコードの一部のみを作成し、あなたの質問にドライブURLを付けることができます。誰でも問題と解決策を見つけ出すことができます。 – Hasya

+0

pushRegistryオブジェクトを.hファイルに保存しないのはなぜですか? AppDelegateにもない理由は?何らかの理由 ? – Hasya

+0

私の更新された答えをチェックしてください、あなたのコードにいくつか変更を加え、このzipをダウンロードしてチェックします。 – Hasya

0

正しく動作するために、ここでは、我々は従う必要がある手順です。

  1. プロジェクトCapaでプッシュ通知を有効にするbilities
  2. は、プッシュ通知

を受信するためのアプリがthis step-by-step tutorialを参照してください許可

  • インターネットにバックグラウンドモード
  • 接続デバイスのリモート通知を有効にします。


    一部のデバイスでのみ起こっているように、3番目と4番目のステップが原因です。

  • 関連する問題