1
0

More than 5 years have passed since last update.

PushKitでVoIPの通知を受ける

Posted at

今までプッシュ通知を受けるには
didRegisterForRemoteNotificationsWithDeviceToken
でdeviceTokenを受け取ってきましたが、PushKitをつかった通知を受ける場合は、まず

- (void)voipRegistration {
    PKPushRegistry *pushRegistry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];
    pushRegistry.delegate = self;
    pushRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
}

とやっておき、PushKitのdelegateを受けるようにします。

- (void)pushRegistry:(PKPushRegistry *)registry didInvalidatePushTokenForType:(NSString *)type;
-(void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type;
-(void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type;

これら3つです。
tokenの登録は

didUpdatePushCredentialsで行います。
[credentials.token description]

として取り出せるので今までと同じようにNSStringとしてPushサーバーのDBなどに保存しておけば良いです。あとはそのtokenに対して、Push通知をしてあげれば、didReceiveIncomingPushWithPayloadが通知のダイアログなどなしにキャッチできますので、ここでVoIPの着信通知などの処理を行えばよいです。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0