0

I am trying to get the Bluemix Cordova Hello World sample working with IBMPushNotifications Service. I have installed the cordova plugins and if I run cordova plugin list I see:

ibm-mfp-core 1.0.10 "MFPCore"
ibm-mfp-push 1.0.12 "MFPPush"

My index.js initialization code looks like this:

  onDeviceReady: function() {
    BMSClient.initialize(app.route, app.guid);
    BMSClient.registerAuthenticationListener("MyRealm", customAuthenticationListener);
   // alert("******** ABOUT TO CALL MFPPush.registerDevice **************");
  // MFPPush.registerDevice(iosPushSettings, pushSuccess, pushFailure); 
    MFPPush.registerDevice({}, pushSuccess, pushFailure);

I do have the MAS customAuthentication service running and working.

I am running the code on an attached iPad via Xcode. I've added some debugPrint statements inside the plugin swift file and see the following messages in the Xcode Console:

"Inside Register Device!!!!!!!"
"Inside registerNotificationsCallback"
"Settings Parameter is not null"
"settings.count == 0"
"about to set notificationSettings"
"About to registerForRemoteNotifications"
"Called registerForRemoteNotifications"

I am not a swift or iOS developer, so I am pretty ignorant on debugging and working with iOS apps. I tried to set breakpoints in the AppDelegate.m file and appears that the code is hitting the breakpoint in didRegisterForRemoteNotificationsWithDeviceToken and I think a token value is getting set. However, I never see my debugPrint code getting triggered in the CDVMFPPush.swift file inside

 func didRegisterForRemoteNotifications(deviceToken: NSData) {
    debugPrint("Inside didRegisterForRemoteNotifications")

or inside

 func didFailToRegisterForRemoteNotifications(error: NSError) {

debugPrint("Inside didFailToRegisterForRemoteNotifications")

As far as I can tell, I have set up the APNS Cert and provisioning profile and I have uploaded my sandboxAPNS.p12 file without any errors into my Bluemix Push service.

On the Bluemix Push Dashboard, if I try to send a push notification to all devices, I receive the following error:

Internal server error. No devices found

I also see PushNotifications enabled in the capabilities tab for my app in XCode.

I am trying to determine why I never see my debugPrint statements for the didRegister or didFailToRegister and why Bluemix does not see my device. Thanks for any suggestions on how to debug and again my apologies for my ignorance on swift and XCode.

JT

Joshua Alger
  • 2,122
  • 1
  • 14
  • 25

1 Answers1

1

OK, I got Push notifications working. It turns out I needed to modify the AppDelegate.m file as per the docs and the Git readme:

    // Register device token with Bluemix Push Notification Service
- (void)application:(UIApplication *)application
     didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{

     [[CDVMFPPush sharedInstance] didRegisterForRemoteNotifications:deviceToken];
}

// Handle error when failed to register device token with APNs
- (void)application:(UIApplication*)application
     didFailToRegisterForRemoteNotificationsWithError:(NSError*)error {

    [[CDVMFPPush sharedInstance] didFailToRegisterForRemoteNotifications:error];
}

// Handle receiving a remote notification
-(void)application:(UIApplication *)application 
    didReceiveRemoteNotification:(NSDictionary *)userInfo 
    fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {

    [[CDVMFPPush sharedInstance] didReceiveRemoteNotification:userInfo];
}