Question

I downloaded the iOS Hello World app and got it working. I am trying to put it into my own app and am having problems subscribing to the channel.

Header:

@property (nonatomic, strong) PNChannel *currentChannel;
@property (nonatomic, strong) PNConfiguration *pubnubConfig;

Implementation:

 _pubnubConfig = [PNConfiguration configurationForOrigin:@"pubsub.pubnub.com" publishKey:@pubKey subscribeKey:subKey secretKey:secKey];
 [PubNub setConfiguration:_pubnubConfig];   
 self.currentChannel = [PNChannel channelWithName:@"tester" shouldObservePresence:NO];

 [PubNub subscribeOnChannel:self.currentChannel withCompletionHandlingBlock:^(PNSubscriptionProcessState state, NSArray *channels, PNError *subscriptionError) {
 NSString *alertMessage = [NSString stringWithFormat:@"Subscribed on channel: %@",self.currentChannel.name];
     if (state == PNSubscriptionProcessNotSubscribedState) {
        alertMessage = [NSString stringWithFormat:@"Failed to subscribe on: %@", subscriptionError ];
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Subscribe" message:alertMessage delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
         [alertView show];
        }    
     }];

I get this error when running: enter image description here

I can't understand why it won't work, especially when most of this is lifted off the demo code. There is no connection problem as the demo project works fine. Would appreciate help, thanks!

Was it helpful?

Solution

You forgot to connect right after +setConfiguration:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top