Xcode 9 - PTPusherErrorDomain error while subscribing to private channel
kumarabhishek9 opened this issue · 2 comments
I am using version ' 1.6.3' in Xcode 9 .
Whenever i try to connect to private channel in simulator for iOS 10/11 I am getting The operation couldn’t be completed. (PTPusherErrorDomain error 1.)
in didFailToSubscribeToChannel
My code is as follows
self.client = [PTPusher pusherWithKey:someKey delegate:self encrypted:YES];
self.client.authorizationURL = [NSURL URLWithString:endpoint];
PTPusherChannel * channel = [self.client subscribeToPrivateChannelNamed:self.channelName];
[channel bindToEventNamed:self.event handleWithBlock:^(PTPusherEvent *channelEvent) {
NSLog(@"i am receiving");
}];
[self.client connect];
-(void)pusher:(PTPusher *)pusher willAuthorizeChannel:(PTPusherChannel *)channel withAuthOperation:(PTPusherChannelAuthorizationOperation *)operation {
//code to generate token
[operation.mutableURLRequest setValue:token forHTTPHeaderField:@"someField"];
- (void)pusher:(PTPusher *)pusher didFailToSubscribeToChannel:(PTPusherChannel *)channel withError:(NSError *)error {
NSLog(@"didFailToSubscribeToChannel ----------------%@", error.localizedDescription);
}
Any idea why it's failing or did I miss anything ?
Is the endpoint that you're using accessible to your simulator device? Could it be that you're not using an HTTPS endpoint and haven't added an exception for it?
Perhaps you're not returning a valid auth body from your auth endpoint? What is your auth endpoint returning to the client?
I was finally able to solve the issue but i had to make a few changes .
1)
self.client = [PTPusher pusherWithKey:someKey delegate:self encrypted:YES];
[self.client connect];
- In
connectionDidConnect
function of the delegate
PTPusherChannel * channel = [self.client subscribeToPrivateChannelNamed:self.channelName];
self.client.authorizationURL = [NSURL URLWithString:endpoint];
When i tried to set authorizationURL
before subscribing to channel I got error Existing subscription to channel
3) In willAuthorizeChannel
function
NSMutableDictionary *mutableDict = [[NSMutableDictionary alloc] init];
//set custom
operation.customRequestParameters = [mutableDict copy];