pusher/libPusher

Data parameter is nil ( on authorize presence channel )

Closed this issue · 3 comments

Hi,

I'm getting this error when I try to subscribe to my presence channel:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'data parameter is nil'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000102eef795 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000102a9d991 objc_exception_throw + 43
    2   CoreFoundation                      0x0000000102eef5ad +[NSException raise:format:] + 205
    3   Foundation                          0x00000001027784a8 +[NSJSONSerialization JSONObjectWithData:options:error:] + 67
    4   LocalChat                           0x00000001000ecb81 -[PTNSJSONParser objectFromJSONData:] + 81
    5   LocalChat                           0x00000001000ecc39 -[PTNSJSONParser objectFromJSONString:] + 121
    6   LocalChat                           0x00000001000f4651 -[PTPusherPresenceChannel subscribeWithAuthorization:] + 177
    7   LocalChat                           0x00000001000ee686 __31-[PTPusher subscribeToChannel:]_block_invoke + 246
    8   LocalChat                           0x00000001000f3716 __57-[PTPusherPrivateChannel authorizeWithCompletionHandler:]_block_invoke + 198
    9   LocalChat                           0x00000001000f6e55 -[PTPusherChannelAuthorizationOperation finish] + 1509
    10  LocalChat                           0x00000001000fb55b -[PTURLRequestOperation connectionDidFinishLoading:] + 91
    11  Foundation                          0x000000010278ee9b __65-[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:]_block_invoke + 48
    12  Foundation                          0x00000001026426ab -[NSURLConnectionInternal _withConnectionAndDelegate:onlyActive:] + 210
    13  Foundation                          0x00000001026425bc -[NSURLConnectionInternal _withActiveConnectionAndDelegate:] + 69
    14  CFNetwork                           0x0000000100c44777 ___ZN27URLConnectionClient_Classic26_delegate_didFinishLoadingEU13block_pointerFvvE_block_invoke + 107
    15  CFNetwork                           0x0000000100c42942 ___ZN27URLConnectionClient_Classic18_withDelegateAsyncEPKcU13block_pointerFvP16_CFURLConnectionPK33CFURLConnectionClientCurrent_VMaxE_block_invoke_2 + 84
    16  CFNetwork                           0x0000000100c85f74 ___ZNK17CoreSchedulingSet13_performAsyncEPKcU13block_pointerFvvE_block_invoke + 25
    17  CoreFoundation                      0x0000000102e96114 CFArrayApplyFunction + 68
    18  CFNetwork                           0x0000000100bb5beb _ZN19RunloopBlockContext7performEv + 115
    19  CFNetwork                           0x0000000100bb5a31 _ZN17MultiplexerSource7performEv + 247
    20  CFNetwork                           0x0000000100bb5854 _ZN17MultiplexerSource8_performEPv + 72
    21  CoreFoundation                      0x0000000102e7eec1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    22  CoreFoundation                      0x0000000102e7e792 __CFRunLoopDoSources0 + 242
    23  CoreFoundation                      0x0000000102e9a61f __CFRunLoopRun + 767
    24  CoreFoundation                      0x0000000102e99f33 CFRunLoopRunSpecific + 467
    25  GraphicsServices                    0x0000000103d843a0 GSEventRunModal + 161
    26  UIKit                               0x0000000101700043 UIApplicationMain + 1010
    27  LocalChat                           0x00000001000158d3 main + 115
    28  libdyld.dylib                       0x00000001035675fd start + 1
    29  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

I am using libpusher 1.5, installed via CocoaPods. Using ios7 and xCode5

I'm subscribing to the channel with this code:

[self.client subscribeToPresenceChannelNamed:self.place.objectId delegate:self];

This is what the auth function on my backend returns. ( the auth function is being invoked )

{"auth":"69c920ed28e119bb585e:60401bfab73d568110adb64d3c181b77edc05af26c5547b725417e03ce06d641","channel_data":"{\"user_id\":\"odRhbWC745\",\"user_info\":{\"username\":\"test\",\"avatarURL\":\"http://files.parse.com/ee5174bf-3d50-49b8-88b8-2466a133600a/89d23b41-9a5d-474e-9a71-6bf7034f8b16-file\",\"displayName\":\"test\"}}"}

Regular public channel subscriptions work fine, as do their binded events. Just seems to be obtaining the auth data thats crashing it.

Been looking through the code and trying to debug this issue.

So it seems the authData that gets used in PTPusherPresenceChannel had a nesting that messed up some of the dictionary keys.

I changed

- (void)subscribeWithAuthorization:(NSDictionary *)authData
{

  [super subscribeWithAuthorization:authData];

  NSDictionary *channelData = [[PTJSON JSONParser] objectFromJSONString:authData[@"channel_data"]];

  self.members.myID = channelData[@"user_id"];
}

To this:

- (void)subscribeWithAuthorization:(NSDictionary *)authData
{

  [super subscribeWithAuthorization:authData];

  NSDictionary *channelData = [[PTJSON JSONParser] objectFromJSONString:authData[@"result"][@"channel_data"]];

  self.members.myID = channelData[@"user_id"];
}

( result was a top level key, not sure where it came from as my backend doesn't have this )

This has stopped my app from crashing, however it doesn't seem like the presence channel is actually subscribing as no delegate methods are being called. ( the delegate has been set )

  • (void)pusher:(PTPusher *)pusher didFailToSubscribeToChannel:(PTPusherChannel *)channel withError:(NSError *)error

is not being called either at the moment.

You need to find out where this result key is coming from. It must be coming from your server. Can you post the full HTTP response from your server?

You're right. I'm using Parse as my backend and they nest the response under a result key. I've gotten that fixed up.

Looks like there was also a problem with my auth function on my backend which is why it wasn't connecting. Its all working now :)

Thanks :)