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

Subscribing to tags does not work

Closed this issue · 5 comments

Bluemix Push service does not support subscribing to more than one tag at a time (see doc).

Example in doc:

curl --request POST
--url 'https://imfpush.au-syd.bluemix.net/imfpush/v1/apps/app_id/subscriptions'
--header 'clientSecret:client_secret'
--data '{"deviceId":"SampleDeviceId","tagName":"Offers"}'
--header 'content-type: application/json'

The current sdk BMSPushClient use of constant IMFPUSH_TAGNAMES = "tagNames" in function subscribteToTags is not recognised by Bluemix. Needs to be changed to "tagName".

Also, the following line in BMSPushClient:subscribeTotags is not aligned to the Bluemix API:

if (status == 207){

Bluemix API indicates it returns a 201 status code upon success.

@tonykambo SDKs will support the multiple tag subscriptions.

@AnanthaKrish - Apologies I'm not clear, are you saying the SDK "will" one day support subscribing to multiple tags? At the moment, it doesn't - Bluemix Push API does not have a resource to subscribe to multiple tags. The current SDK code attempts to pass a body attribute that is being rejected by Bluemix ("tagNames" instead of "tagName" ). I've had to make a couple of fixes to the sdk code to get this to work right now:

  1. Change the data body from "tagNames" to "tagName"
  2. Change the success status code from 207 to 201 in checking the response from Bluemix

As such I still see this as an open issue, not sure why it was closed. Would you mind re-opening please so this issue can be tracked through to a fix? Perhaps rename the function to "subscribeToTag" (singular) and then add "subscribeToTags" (plural) when the multiple tag subscription is added (perhaps using OperationQueue/Operations to send multiple requests given Bluemix only supports one tag at a time). Am I missing something here?

@tonykambo We are supporting the multiple tags subscription from Swift SDK. This is not an issue.

To register multiple tags you can use the same subscribe method and the body will be like this,

{
  "deviceId": "TestDeviceId",
  "tagNames": ["tag1","tag2"]
}

If you want to register single tag at a time, please change the body to,

{
  "deviceId": "TestDeviceId",
  "tagName": "tag1"
}

@AnanthaKrish I can see the hidden API. Not sure why it is hidden. That aside, there is another issue with both the subscribeToTag and unsubscribeFromTag.

When passing an array of just one tag both subscribeToTag and unsubscribeFromTag break up the single tag name into an array of single characters.

For example, a single tag "StatusReminder" is passed and this code snippet in unsubscribeFromTags():

let mappedArray = tagsArray.flatMap{"($0)"}.description;
let data = "{"(IMFPUSH_TAGNAMES)":(mappedArray), "(IMFPUSH_DEVICE_ID)":"(devId)"}".data(using: .utf8)

produces this:

[ERROR] [7E5......41AA0] sendAnalyticsData(logType:logStringData:) in /..../Pods/BMSPush/Source/BMSPushClient.swift:1016 :: Entering: unsubscribeFromTags
Unsubscribe data = {"tagName":["S", "t", "a", "t", "u", "s", "R", "e", "m", "i", "n", "d", "e", "r"], "deviceId":"7E50.....FB441AA0"}

I believe the flatMap line should be changed to something like this:

let mappedArray = tagsArray.flatMap({$0 as? String})

@tonykambo I am not able to recreate the issue you are mentioning. I am using Xcode 9.0.1 and tested the same scenario in swift3.2 as well ass swift 4.0 ... are you passing an array of strings to the sdk in subscribeToTag and unsubscribeFromTag methods ?