3

I'm using the new push-notification service on bluemix, with an iOS device.

The device registers successfully. When I check with the REST-API, I see the device-ID, token and so on.

However, running the iOS-app on the device crashes the app on first run and registration.

The crash happens in CDVMFPPush.swift in func didRegisterForRemoteNotifications(deviceToken: NSData) on line 309 (let pushToken = response.responseJson["token"] as! String).

I did a print(response) in this function and it seems that responseJson only contains the deviceId and the userId. The token is missing. When I use the REST-Api again to do the same request, the response seems to be complete.

I think that because of this error the push registration doesn't finish, as I don't receive any notifications when I try to run the service in sandbox-mode.

Any ideas?

(P.S. I checked this solution - iOS Application crashes when trying to register the device to IBM Mobile First Push service on Bluemix - the linker flag is set [-ObjC])

Here's the request from my console (app-id/secret/device is edited)

Response text: {"createdTime":"2016-06-07T15:28:55Z","lastUpdatedTime":"2016-06-07T15:28:55Z","createdMode":"API","deviceId":"xxxx","userId":"","token":"xxxx","platform":"A","href":"https://myapp.mybluemix.net:443/imfpush/v1/apps/xxxx/devices/xxxx"}
httpStatus: 201
responseHeaders: {
    Connection = "Keep-Alive";
    "Content-Type" = "application/json";
    Date = "Tue, 07 Jun 2016 15:28:55 GMT";
    Location = "https://myapp.mybluemix.net:443/imfpush/v1/apps/xxxx/devices/xxxx";
    "Transfer-Encoding" = Identity;
    "X-Backside-Transport" = "OK OK";
    "X-Global-Transaction-ID" = xxxx;
    "X-Powered-By" = "Servlet/3.0";
}
responseJson: {
    deviceId = "xxxxx";
    userId = "";
}
Community
  • 1
  • 1
Swissdude
  • 3,486
  • 3
  • 35
  • 68
  • Could you please clarify what you mean when you say the device registers successfully but when you use the iOS-app it does not? What means of registration are you using that does work? When you say the iOS-app are you referring to a bluemix sample or custom code? – James Young IBM Jun 07 '16 at 18:44
  • I get a message in the xcode console, that the device registered successfully. Also, when I check with the REST-Api, I can see the device's ID in the devices list (when I delete it via REST, I can register it again, with the same ID). When I try to send a test-message (via REST or PHP), the device doesn't show the notification, although I get a «message sent successfully» message from the service. And it's custom code, made with cordova. I don't know if this is all related. What really matters is, that the app crashes at the above mentioned line when the device first registers. – Swissdude Jun 07 '16 at 19:40
  • If you'd like to rerun the application and pass me your application ID (meant to be public facing) I can look at our Push service backend logs to see what is prompting it to send that incorrect response json. If you do not feel comfortable in doing that or in the meantime I would recommend trying to run the hellopush cordova sample and seeing if that works correctly for you. https://github.com/ibm-bluemix-mobile-services/bms-samples-cordova-hellopush – James Young IBM Jun 08 '16 at 15:15
  • Thanks for your answer. It seems that the Bluemix-Service is returning the correct and complete JSON-Set (I can see that in the console - responseJson and «Response text:» are both returning the complete set). It is only in the didRegisterForRemoteNotifications(deviceToken : NSData)-Method where the response.responseJson doesn't receive the complete set, but only the userId and deviceId. I'm gonna check the hellopush-app and see if it happens there as well... – Swissdude Jun 10 '16 at 14:18
  • Ok, I installed and tested the hellopush-app - and I got the same result. On a fresh register, the app crashes at the exact same place in didRegisterForRemoteNotifications on line 307 - let pushToken = response.responseJson["token"] as! String - token is not available. – Swissdude Jun 10 '16 at 14:51
  • Addendum: I use the original app that I used for the old Push-Service already and just linked the new Push-Service with this app. Might this be the cause of the problem? – Swissdude Jun 10 '16 at 15:10
  • Uh - James Young IBM - did you forget about me? ;) – Swissdude Jun 16 '16 at 11:51
  • Sorry about that. When you say you use the original app are you talking about the front-end cordova app or the backend app on Bluemix? Same backend wouldn't matter, but old bluemix cordova plugins might cause issues alongside the new ones. – James Young IBM Jun 16 '16 at 13:29
  • Thanks for replying. I now added a new app on bluemix and connected it to the new Push-Service - with the same result. Again, I tried the hellopush-example with the same result. The app crashes at the afformentioned line. When I print out the IMFResponse it clearly shows that the token is missing. Also, a «response.responseText» gives me NULL. I am, however, using the latest cordova-SDK to build the app. It seems like IMFResponse+IMFPushCategory.h from the IMFPush.framework returns an invalid IMFResponse. – Swissdude Jun 16 '16 at 14:48
  • I realized, that on the second run, the token is returned by IMFResponse - so this really happens if the app registers itself newly and on first run. Maybe this helps – Swissdude Jun 16 '16 at 15:25
  • I'm having trouble recreating. I have a few questions to try to narrow down this problem to a service, SDK, or configuration error: – joe Jun 17 '16 at 17:37
  • 1. I would try creating a new push notifications service and try to add APNS, etc. to the service (https://new-console.ng.bluemix.net/docs/services/mobilepush/index.html). – joe Jun 17 '16 at 17:37
  • 2. Could you try running the Objective C hellopush app with your sample: (https://github.com/ibm-bluemix-mobile-services/bms-samples-ios-hellopush) This uses the IMFPush libraries that your Cordova app is using, and if this doesn't run it would suggest that the problem is not with Cordova. – joe Jun 17 '16 at 17:38
  • 3. You may also want to run the Swift hellopush app (https://github.com/ibm-bluemix-mobile-services/bms-samples-swift-hellopush) The IMFPush libraries are being replaced with BMSPush soon and the Cordova SDK will be updated to reflect that. If the Swift SDK works, then there is probably something wrong with the old SDKs that will need some more investigation. – joe Jun 17 '16 at 17:38
  • Another useful comment would be the version numbers of everything you're using (XCode, Cordova, etc.) – joe Jun 17 '16 at 17:48
  • Also, one more thing I forgot to mention--you said that you were migrating from the old Push service. Did you remove the old Cordova plugins? There could be some conflicts in your Cordova plugins causing the error. – joe Jun 17 '16 at 19:22
  • Thanks for replying... 1) I did that already - no effect --- 2) did this as well. Same effect as in my original app - throws an error on first run --- 3) just did this. App says: «Error - A server with the specified hostname could not be found» - doesn't say which specified hostname, though. --- 4) XCode Version is 7.3.1 - Cordova Version is ios 3.9.2 --- 5) Old Cordova-Plugins have been removed... – Swissdude Jun 21 '16 at 14:57
  • One more thing as well: The swift-app requires a «bluemixRegion» in the app-delegate. But I couldn't find anything in the documentation where this value could be found... – Swissdude Jun 21 '16 at 15:08
  • Regarding the bluemixRegion, I think that's something that was added pretty recently. There are some global variables in BMSClient you can use depending on your region, so BMSClient.REGION_UK for EU-GB for example. – James Young IBM Jun 22 '16 at 14:43
  • Don't know whether this helpled. In the Swift-testPush app I still get this error: «Error while verifying previous registration - Error is: A server with the specified hostname could not be found». Alas, the app-route should be ok. At least, that's what the dashboard tells me. – Swissdude Jun 24 '16 at 12:40
  • Still no idea on this? I'm getting a little frustrated... :( – Swissdude Jun 30 '16 at 07:33
  • @Swissdude James is looking into your issue. Just so you know, I just recently answered a question setting up Push Notifications for iOS from Cordova here: http://stackoverflow.com/questions/38240745/unable-to-run-bms-samples-cordova-hellopush-bms-samples-cordova-push-swift-h-f/38254448#38254448 – joe Jul 21 '16 at 05:19
  • Try connecting this to the Mobile Services Starter application (with a fresh Push Notifications service) on Bluemix. Then, you can test it from an actual iOS device – joe Jul 21 '16 at 05:36
  • When you visit the App Route from your Mobile Services Starter application, you should be greeted with the page at the beginning of this YouTube video: https://www.youtube.com/watch?v=fAM0wOfvelY – joe Jul 21 '16 at 05:36
  • Thanks Joe. As suggested, I opened a ticket on Bluemix and I'm in contact with the support staff. The thing is, it's «kinda» working. The device registers itself on the bluemix service and I can access it via REST-API. The main issue is, that on first, clean run, when the device registers itself, the app crashes (and I repeated that issue with the hello push app). IBM staff says they cannot reproduce the error, though... – Swissdude Jul 21 '16 at 13:54
  • When we get the answer, someone on the team can post the updated solution to this problem (or I'll update mine). Speaking from experience from doing Cordova -> iOS, I know that I've forgot to change a small build setting and got caught in a rabbit hole trying to debug the application and talking to the developers to see why the code wasn't hitting a break point. So now I'm extra cautious when going through all the steps :0) – joe Jul 22 '16 at 05:50

1 Answers1

1

We've updated the MFPPush iOS Framework to resolve the issue and the MFPPush Cordova Plugin has been updated to incorporate these fixes. We suspect the crashes were caused by the fact that you were being sent a second IMFResponse object through the callback and this second IMFResponse's responseJson didn't have the token as you saw which was resulting in the crash. These changes should resolve that issue.

Easiest way to update the plugin is just to remove the old and re-add it, you should be on version 1.0.14 of ibm-mfp-push to see the fixes.

Can see the update on the related Github as of this morning as well https://github.com/ibm-bluemix-mobile-services/bms-clientsdk-cordova-plugin-push

James Young IBM
  • 616
  • 1
  • 5
  • 13
  • Thanks James. Installed the update and the app doesn't crash anymore. I removed the plugin via cordova and added it again as suggested. However, when I do a «cordova plugin list» it still shows me the old version (1.0.13) of the plugin? Strange... But nevertheless, the problem seems to be solved – Swissdude Jul 29 '16 at 08:35