distriqt / ANE-Parse

Provides access to the Parse SDK
https://airnativeextensions.com/extension/com.distriqt.Parse
Other
0 stars 0 forks source link

app crashes/closes if notification received whilst open on iOS #16

Closed SeanJD closed 8 years ago

SeanJD commented 8 years ago

I've built my app for iOS and android. Android's fine and behaves as expected but on iOS if the app's open when it receives a PN from Parse then the app crashes/closes. I've tested on an iPhone 4S, iOS 8.3 and an iPhone 5s, iOS 8.4.1. Same thing happens on both. If I receive a PN from another source (i.e. facebook) when the app's open it's fine - the PN slides in over the top of the app, but as soon as it gets one registered to itself it bombs out. It may be that I'm missing something but have gone through the TestParse example and am pretty sure it's set up as should be - also as I say it works fine on regitsering the device/installation and receiving PN's from APN - it's only if the app's open that it crashes. Any ideas?

Thanks

SeanJD commented 8 years ago

I'm compiling with the ASC 20.0 SDK I've updated the iPhone 4s to iOS 9.2.1 and it's still crashing when a PN comes through (it bings and vibrates at the same time as the app crashing out). I'm not developing on a mac so can't use x-code to view the crash-log

marchbold commented 8 years ago

What payload are you sending in the push notification? Are you using a custom JSON or just the simple parse push notification?

SeanJD commented 8 years ago

It's a simple notification. Both from my cloudcode call (see below) but also if i send a push directly from the Parse dashboard.

Parse.Push.send({ where: installationQuery, data: { alert: message//message is a simple string value } }, { success: function() { }, error: function(error) { } });

SeanJD commented 8 years ago

I've worked through to the cause of this issue. I was under the impression the app only needed to call the Parse.service.setupApplication and Parse.service.register methods once (on first registering the installation) so had written a command call to only do this once (using persistent data to store it and skip if it's already been successfully registered).

I was always calling Core.init & Parse.init(key) & registering the notification and error handlers.

This seemed to work and the OS would receive notifications but was the cause of it crashing out (on iOS only) when a new PN came through.

I now call the methods Parse.service.setupApplication(ParseConfig.APPLICATION_ID, ParseConfig.CLIENT_KEY, false); Parse.service.register(false); every time the application starts and that has solved it.

My bad, apologies for this, I just thought the above only had to be called when first registering the app/device with Parse/APN/GCM and was a waste to call it every time. Turns out it isn't!

Hopefully this info will come in useful for others making the same mistake in the future.

marchbold commented 8 years ago

Hi,

Yes, sorry if that wasn't clear but those functions need to be called each run of your application as they check the setup of your application and load information from memory / storage if required.

I'll make sure this is clear in the documentation.

Cheers.

gameaccount commented 8 years ago

Hi guys. I'm having the same problem, i.e. my app crashes when launching from clicking a push notification. However my app is crashing as soon as I call setupApplication(), so I don't even get a chance to call register(). The launches fine when I launch normally. Any ideas what I might be doing wrong?

My AS3 code looks like this:

`protected function init( ):void { try { Core.init(); trace("ParseNotificationController:init _appKey = " + _appKey ); Parse.init( _appKey );

            trace( "Parse Supported: " + Parse.isSupported );

            if (Parse.isSupported)
            {
                trace( "Parse Version:   " + Parse.service.version );
                trace("ParseNotificationController:init _parseAppId = " + _parseAppId );
                trace("ParseNotificationController:init _parseClientKey = " + _parseClientKey );

                Parse.service.addEventListener( ParseEvent.NOTIFICATION, parse_notificationHandler );
                Parse.service.addEventListener( ParseEvent.FOREGROUND_NOTIFICATION, parse_notificationHandler );
                Parse.service.addEventListener( ParseEvent.BACKGROUND_NOTIFICATION, parse_notificationHandler );

                Parse.service.addEventListener( ParseEvent.REGISTERING,         parse_printEventHandler );
                Parse.service.addEventListener( ParseEvent.REGISTER_SUCCESS,    parse_registerHandler );
                Parse.service.addEventListener( ParseEvent.UNREGISTERED,        parse_printEventHandler );

                Parse.service.addEventListener( ParseEvent.ERROR, parse_errorHandler );
                trace("ParseNotificationController:init setupApplication" );
                Parse.service.setupApplication( _parseAppId, _parseClientKey );         
                trace("ParseNotificationController:init register" );
                Parse.service.register(false);
            }

        }
        catch (e:Error)
        {
            trace( "ERROR:" + e.message );
        }
    }

`

Output from xcode is;

: Parse Supported: true : Parse Version: 2.8.iOS.1.9 : ParseNotificationController:init _parseAppId = uBMha2ty6RtVfi8Lnq4n3UpONiyMCgMOYYhbDe0v : ParseNotificationController:init _parseClientKey = oHFQGzfG9cxBdausBthSiu97316eEbD74ggNkJN7 : ParseNotificationController:init setupApplication : com.distriqt.Parse::PushNotificationsManager::didFinishLaunchingWithOptions : com.distriqt.Parse::handleRemoteNotification: userInfo startup: 1 : com.distriqt.Parse::ParseProcessNotification():Received remote notification : [{ "aps" : { "alert" : "test", "sound" : "default" }, "parsePushId" : "V7IaRx7Xm7" }] : **\* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '**\* setObjectForKey: key cannot be nil' **\* First throw call stack: (0x183361900 0x1829cff80 0x18324cec0 0x10068b0e0 0x182db55f0 0x182dc089c 0x10068b024 0x1006ad318 0x1006f2994 0x1006f2d34 0x100709448 0x1006714b0 0x182db5630 0x182db55f0 0x182dc3a88 0x182dc3224 0x182fc9470 0x182fc9020)
marchbold commented 8 years ago

@gameaccount Could you start a new issue for this? also make sure you are using the latest version of the Parse and Bolts ANEs. Cheers