Cannot Delete App Token from Push Notification Service

0 votes

Our app very much needs to be able to unsubscribe a device token from the Push Notification Service. I see on the online docs that there is a function on other platforms called deleteDeviceToken(). Unfortunately, this function does not exist in the Cocos2d-x version of the App42 API. Is there a possible workaround, perhaps by creating a custom function to do this?

asked May 9, 2014 in App42 Cloud API-BaaS by David Harrison Turpi (23 points)

2 Answers

+1 vote
 
Best answer

It is in our pipeline and our next release will have all the APIs.

For now, you can add below written method in PushNotificationService class:

In PushNotificationService.h:(cocos2d-x version 2.2.2)

void DeleteDeviceToken(string deviceToken, string userName, CCObject* pTarget, cocos2d::SEL_CallFuncND pSelector);

In PushNotificationService.cpp:(cocos2d-x version 2.2.2)

void PushNotificationService::DeleteDeviceToken(string deviceToken, string userName, CCObject* pTarget, cocos2d::SEL_CallFuncND pSelector)

{

    App42PushNotificationResponse *response = new App42PushNotificationResponse::App42PushNotificationResponse(pTarget,pSelector);    

    try

    {

        Util::throwExceptionIfStringNullOrBlank(userName, "User Name");

        Util::throwExceptionIfStringNullOrBlank(deviceToken, "Device Token");

        Util::throwExceptionIfTargetIsNull(pTarget, "Callback's Target");

        Util::throwExceptionIfCallBackIsNull(pSelector, "Callback");

    }

    catch (App42Exception *e)

    {

        std::string ex = e->what();

        response->httpErrorCode = e->getHttpErrorCode();

        response->appErrorCode  = e->getAppErrorCode();

        response->errorDetails  = ex;

        response->isSuccess = false;

        if (pTarget && pSelector)

        {

            (pTarget->*pSelector)((cocos2d::CCNode *)pTarget, response);

        }

        delete e;

        e = NULL;

        return;

    }

    /**

     * Creating SignParams and signature

     */

    map<string, string> signParams;

    string timestamp = Util::getTimeStamp();

    populateSignParams(signParams);

    signParams["userName"] = userName;

    signParams["deviceToken"] = deviceToken;

    string signature = Util::signMap(secretKey, signParams);    

    /**

     * Creating URL

     */

    string resource = "push";

    string baseUrl = getBaseUrl(resource);

    baseUrl.append("?");    

    /**

     * Creating Query Params

     */

    map<string, string> queryParams;

    queryParams["userName"] = userName;

    queryParams["deviceToken"] = deviceToken;

    string queryString = buildQueryString(queryParams);

    baseUrl.append(queryString);

    /**

     * Creating Headers

     */

    std::vector<std::string> headers;

    map<string, string> metaHeaders;

    populateMetaHeaderParams(metaHeaders);

    Util::BuildHeaders(metaHeaders, headers);

    Util::BuildHeaders(apiKey, timestamp, VERSION, signature, headers);

       /**

     * Initiating Http call

     */

    Util::executeDelete(baseUrl, headers, response, callfuncND_selector(App42PushNotificationResponse::onComplete));

}

 
answered May 10, 2014 by rajeev.etc (1,660 points)
selected May 12, 2014 by David Harrison Turpi
This worked! Thank you very much!! Looking forward to the updated API.
+1 vote

If you are using cocos2d-x version 3.0 then use this code:

In PushNotificationService.h:(cocos2d-x version 3.0)

void DeleteDeviceToken(string deviceToken, string userName, Object* pTarget, cocos2d::SEL_CallFuncND pSelector);

In PushNotificationService.cpp:(cocos2d-x version 3.0)

void PushNotificationService::DeleteDeviceToken(string deviceToken, string userName, Object* pTarget, cocos2d::SEL_CallFuncND pSelector)

{

    App42PushNotificationResponse *response = new App42PushNotificationResponse::App42PushNotificationResponse(pTarget,pSelector);

    try

    {

        Util::throwExceptionIfStringNullOrBlank(userName, "User Name");

        Util::throwExceptionIfStringNullOrBlank(deviceToken, "Device Token");

        Util::throwExceptionIfTargetIsNull(pTarget, "Callback's Target");

        Util::throwExceptionIfCallBackIsNull(pSelector, "Callback");

    }

    catch (App42Exception *e)

    {

        std::string ex = e->what();

        response->httpErrorCode = e->getHttpErrorCode();

        response->appErrorCode  = e->getAppErrorCode();

        response->errorDetails  = ex;

        response->isSuccess = false;

        if (pTarget && pSelector)

        {

            (pTarget->*pSelector)((cocos2d::Node *)pTarget, response);

        }

        delete e;

        e = NULL;

        return;

    }

    /**

     * Creating SignParams and signature

     */

    map<string, string> signParams;

    string timestamp = Util::getTimeStamp();

    populateSignParams(signParams);

    signParams["userName"] = userName;

    signParams["deviceToken"] = deviceToken;

    string signature = Util::signMap(secretKey, signParams);

    /**

     * Creating URL

     */

    string resource = "push";

    string baseUrl = getBaseUrl(resource);

    baseUrl.append("?");

    /**

     * Creating Query Params

     */

    map<string, string> queryParams;

    queryParams["userName"] = userName;

    queryParams["deviceToken"] = deviceToken;

    string queryString = buildQueryString(queryParams);

    baseUrl.append(queryString);

    /**

     * Creating Headers

     */

    std::vector<std::string> headers;

    map<string, string> metaHeaders;

    populateMetaHeaderParams(metaHeaders);

    Util::BuildHeaders(metaHeaders, headers);

    Util::BuildHeaders(apiKey, timestamp, VERSION, signature, headers);

    /**

     * Initiating Http call

     */

    Util::executeDelete(baseUrl, headers, response, httpresponse_selector(App42PushNotificationResponse::onComplete));

}

 
answered May 10, 2014 by rajeev.etc (1,660 points)
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...