2016-05-08 13 views
2

私のiOSアプリケーションでVoIP通知を実装したいですが、didUpdatePushCredentialsメソッドが決して呼び出されず、デバイストークンを取得できません。didUpdatePushCredentialsが呼び出されない

私はアプリケーションでAPNSを実装しましたが、これらの2つのサービスが競合しますか?

は、ここで私は、リモート通知が有効になって私のAppDelegateコード

- (void)application:(UIApplication *)application 
    didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings { 
    LOGI(@"%@", NSStringFromSelector(_cmd)); 

    //register for voip notifications 
    self->pushRegistry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()]; 
    [self->pushRegistry setDelegate:self]; 
    [self->pushRegistry setDesiredPushTypes:[NSSet setWithObject:PKPushTypeVoIP]]; 

    NSLog(@"VoIP push registered"); 

} 

#pragma mark - VoIP push methods 

- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type { 
    NSLog(@"voip token: %@", credentials.token); 
} 

- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type { 
    NSDictionary *payloadDict = [payload.dictionaryPayload valueForKey:@"aps"]; 
    NSString *message = (NSString *)[payloadDict valueForKey:@"alert"]; 

    if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) { 
     UILocalNotification *localNotification = [[UILocalNotification alloc] init]; 
     localNotification.alertBody = [message stringByAppendingString:@" - voip"]; 
     localNotification.applicationIconBadgeNumber = 1; 
     localNotification.soundName = @"notes_of_the_optimistic.caf"; 

     [[UIApplication sharedApplication] presentLocalNotificationNow:localNotification]; 
    } else { 
     dispatch_async(dispatch_get_main_queue(), ^{ 
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"VoIP notification" message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; 
      [alert show]; 
     }); 
    } 


    NSLog(@"incoming voip notfication: %@", payload.dictionaryPayload); 
} 

- (void)pushRegistry:(PKPushRegistry *)registry didInvalidatePushTokenForType:(NSString *)type { 
    NSLog(@"Voip token invalidate"); 
} 
  • で、証明書とプロビジョニングプロファイルがインストールされています。
  • APNSを使用して標準通知をプッシュできます。

解決方法はありますか?

答えて

1

を忘れてしまった証明書に問題がありました。

証明書を再生成して再インポートし、問題を修正しました。

+0

私はすでにそれを再生成します。しかし、同じ問題です。 –

+0

@KishanVyasプッシュ証明書を作成するときに証明書が必要です。正しい証明書を選択してください。 –

+0

私はすでに正しい証明書を作成しました。 –

2

以下のコードを使用して、以下のことを確認してください。

コールdidFinishLaunchingWithOptions

その他deleget方法における法の下

**`**// Register for VoIP notifications**`** 

- (void) voipRegistration { 
    dispatch_queue_t mainQueue = dispatch_get_main_queue(); 
    // Create a push registry object 
    _voipRegistry = [[PKPushRegistry alloc] initWithQueue: mainQueue]; 
    // Set the registry's delegate to self 
    [_voipRegistry setDelegate:(id<PKPushRegistryDelegate> _Nullable)self]; 
    // Set the push type to VoIP 
    _voipRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP]; 
} 
)プロジェクト機能

1でこのことについて確認してください

- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials: (PKPushCredentials *)credentials forType:(NSString *)type { 
    // Register VoIP push token (a property of PKPushCredentials) with server 

    if([credentials.token length] == 0) { 
     NSLog(@"voip token NULL"); 
     return; 
    } 
    NSLog(@"%@",credentials.token); 
} 

//に続くバックグラウンドモードは

ONであるとして、

2)VOIP

3)背景

4をフェッチ)remotenotification

5)いけないが、バックグラウンドモードの内側デリゲート

をインポートする

+0

私は、同じ手順に従って、これらのステップはまた、Sinchで言及されています。しかし、まだ同じ問題に直面しています。 –

5

新しいxcode(xcode 9を使用しています)を実行している場合、VOIPはCapabilitiesタブのBackgroundセクションにありません。これにより、didUpdatePushCredentialsが呼び出されなくなります。

あなたのplistに行かなければならないのですが、Required Background ModesにはApp provides Voice over IP servicesを追加する必要があります。

アップルがこれをやってくれたとは思えません。私はこの簡単な修正を探して8時間労働日を無駄にしました。

enter image description here

+0

私は既にこれをinfo.plistファイルに追加しました。しかし、まだ私はこれを取得しています。 –

関連する問題