0

I want to add my app custom token in Pusher header. Below is my code.

OCAuthMethod *authMethod = [[OCAuthMethod alloc] initWithAuthEndpoint:kPushedWebHockUrl];
OCPusherHost *host = [[OCPusherHost alloc] initWithCluster:kPusherClusterId];
PusherClientOptions *options = [[PusherClientOptions alloc] initWithOcAuthMethod:authMethod attemptToReturnJSONObject:YES autoReconnect:YES ocHost:host port:nil encrypted:YES activityTimeout:nil];
self.pusher = [[Pusher alloc] initWithAppKey:kPusherKey options:options];
self.pusher.connection.delegate = self;
[self.pusher connect];
Ajith Kumar
  • 1,202
  • 1
  • 10
  • 22

1 Answers1

0

If you trying to make an Authorized connection for Pusher, then try using the PTPusherChannelAuthorizationDelegate by which you can make the authentication API and share the response data to Pusher.

You can set the delegate for the Pusher object as

pusher.channelAuthorizationDelegate = self

Then implement the deleagte function in your class

func pusherChannel(_ channel: PTPusherChannel!, requiresAuthorizationForSocketID socketID: String!, completionHandler: PTPusherChannelAuthorizationCallback!) {


  //create API call with your custom header.You can use URLSession, Alamofire  or something like that. Once you get success response call the completionHandler.
     

 completionHandler(true,response,nil)
}

Hope this helps.

Sujith Chandran
  • 2,671
  • 1
  • 15
  • 13