ibm-bluemix-mobile-services/bms-clientsdk-swift-push

Cannot register the device token to the BMSPushClient

Closed this issue · 7 comments

Chiu1 commented
  • Using BMSCore (2.3.5)
  • Using BMSPush (3.3.2)
    Cannot use the method registerWithDeviceToken in my objective-c base project.

I am trying to migrate the IMFPush to BMSPush but the genearted BMSPushClient-Swift.h are not include the registerWithDeviceToken method. I have tried to decare the function manully but the IDE report the message as below.

@objc(registerWithDeviceToken:withUserId:)
public func registerWithDeviceToken (deviceToken:Data, completionHandler: @escaping(_ response:String?, _ statusCode:Int?, _ error:String) -> Void) {
        if (isInitialized){

Method cannot be marked @objc because the type of the parameter 2 cannot be represented in Objective-C

Lastly, May i have the migration grade from IMFPush to BMSPush in objectie-C based cordova project.

@Chiu1

  1. We don't support objective-c..
  2. are you using the cordova push plugin ? if yes , which version are you using ?
Chiu1 commented

@AnanthaKrish
Thanks for your reply,
On the #1 we are integrating the mobile first SDK into the existing Cordova project. But we find they are using the IMFCore and IMFPush framework. Once we install the mobile first plugin, there will crash and show4 the duplicate class issue on PSecurityUtils, WLUtils etc.
On the #2, IMFCore and IMFPush. Cannot find the version.

@Chiu1 The IBM Cloud push notifications plugin is bms-push and the core plugin is bms-core. IMFCore and IMFPush are no longer supported . For push notifications service, try using the bms-push plugin.

Chiu1 commented

@AnanthaKrish May I know is there have any migration guide from IMFPush to BMS-push in Objective-C based project. And is it blog still possible?

@Chiu1 I will check that and get back to you .
By the way bms-push supports objective-C. If you are using only push notifications service, please try to remove the old plugin and add the bms-push .

Chiu1 commented

@AnanthaKrish
I have solved the issue by creating a custom BMSSDKbridge.swift.
But is that have any logic change within the PushClient, because I follow the existing implementation to migrate the IMF to BMS will cause the infinite loop on didRegisterForRemoteNotificationsWithDeviceToken:.

Here is the code

Production implementation with IMFCore and IMFPush

- (void) didFinishLaunchingWithOptions:(NSNotification *)notification {
IMFClient *imfClient = [IMFClient sharedInstance];
[imfClient initializeWithBackendRoute:BLUEMIX_ROUTE backendGUID:BLUEMIX_APP_GUID];
...
}

- (void) didRegisterForRemoteNotificationsWithDeviceToken:(NSNotification *)deviceToken {
...
IMFPushClient *push = [IMFPushClient sharedInstance];
[push initializeWithAppGUID:BLUEMIX_APP_GUID clientSecret:BLUEMIX_CLIENT_SECRET];
[push registerWithDeviceToken:_deviceToken completionHandler:^(IMFResponse *response, NSError *error) {
        ....
    }];
}

I have change to this version to prevent the infinite loop

- (void) didFinishLaunchingWithOptions:(NSNotification *)notification {
[BMSClientObjc initializeWithBackendRoute:BLUEMIX_ROUTE backendGUID:BLUEMIX_APP_GUID region:BMSClientObjc.REGION_SYDNEY];
[BMSPushClientObjc initializeWithAppGUID:BLUEMIX_APP_GUID clientSecret:BLUEMIX_CLIENT_SECRET];
...
}

- (void) didRegisterForRemoteNotificationsWithDeviceToken:(NSNotification *)deviceToken {
...
[BMSPushClientObjc registerWithDeviceToken:_deviceToken completionHandler:^(NSString * responseJson, NSNumber * statusCode, NSString * error) {
       ...
    }];
}

@Chiu1 There are modifications . BMS SDK will take care of Apple pushnotifications register calls from the iPhone. If you call those methods , definitely it will lead into loops. But it won't be infinite loops. The above one is correct .