Метод IBM MFP onReadyToSubscribe не вызывается

У меня есть гибридное приложение для iOS, написанное на IBM MFP 7.1 с angular. В настоящее время я пытаюсь использовать push-уведомления, но код никогда не входит в метод onReadyToSubscribe.

Я получаю весь код из документации о push-уведомлениях, и у меня все еще есть проблема.

Мой application-descriptor.xml

 <application xmlns="http://www.worklight.com/application-descriptor" id="B" platformVersion="7.1.0.00.20151227-1725">
<displayName>A</displayName>
<description>A</description>
<author>
    <name>application's author</name>
    <email>application author's e-mail</email>
    <homepage>http://mycompany.com</homepage>
    <copyright>Copyright My Company</copyright>
</author>
<mainFile>index.html</mainFile>
<features/>
<thumbnailImage>common/images/thumbnail.png</thumbnailImage>

<ipad bundleId="xxx.xxx.xxx"  version="1.0" securityTest="PushSecurityTest"  >
    <worklightSettings include="false"/>
    <pushSender password="123456"/>
    <security>
        <encryptWebResources enabled="false"/>
        <testWebResourcesChecksum enabled="false" ignoreFileExtensions="png, jpg, jpeg, gif, mp4, mp3"/>
    </security>
</ipad>

main.js file the one where we should have the magic

    function wlCommonInit() {

    PushAppRealmChallengeHandler.init();

    WL.Client.connect({
        onSuccess: connectSuccess, 
        onFailure: connectFailure
    });

     //---------------------------- Set up push notifications -------------------------------
    if (WL.Client.Push) {   
        WL.Client.Push.onReadyToSubscribe = function() {

            WL.SimpleDialog.show("Push Notifications", "onReadyToSubscribe", [ {
                text : 'Close',
                handler : function() {}
              }
              ]);

            $('#SubscribeButton').removeAttr('disabled');
            $('#UnsubscribeButton').removeAttr('disabled');

            WL.Client.Push.registerEventSourceCallback(
                "myPush", 
                "PushAdapter", 
                "PushEventSource", 
                pushNotificationReceived);
        };
    }
}

function connectSuccess() {
    WL.Logger.debug ("Successfully connected to MobileFirst Server.");
}

function connectFailure() {
    WL.Logger.debug ("Failed connecting to MobileFirst Server.");
    WL.SimpleDialog.show("Push Notifications", "Failed connecting to MobileFirst Server. Try again later.", 
            [{
                text : 'Reload',
                handler : WL.Client.reloadapp
            },
            {
                text: 'Close',
                handler : function() {}
            }]
        );
}
function loginButtonClicked() {
    var reqURL = '/j_security_check';

    var options = {
        parameters : {
                j_username : $('#usernameInputField').val(),
                j_password : $('#passwordInputField').val()
        },
        headers: {}
    };

    PushAppRealmChallengeHandler.submitLoginForm(reqURL, options, PushAppRealmChallengeHandler.submitLoginFormCallback);
}

function isPushSupported() {
    var isSupported = false;
    if (WL.Client.Push){
        isSupported = WL.Client.Push.isPushSupported();
    }   

    alert(isSupported);
    WL.SimpleDialog.show("Push Notifications", JSON.stringify(isSupported), [ {
        text : 'Close',
       handler : function() {}}
    ]);
}

function isPushSubscribed() {
    var isSubscribed = false;
    if (WL.Client.Push){
        isSubscribed = WL.Client.Push.isSubscribed('myPush');
    }

    WL.SimpleDialog.show("Push Notifications", JSON.stringify(isSubscribed), [ {
        text : 'Close',
        handler : function() {}}
    ]);
}

// --------------------------------- Subscribe ------------------------------------
function doSubscribe() {
    WL.Client.Push.subscribe("myPush", {
        onSuccess: doSubscribeSuccess,
        onFailure: doSubscribeFailure
    });
}

function doSubscribeSuccess() {
    WL.SimpleDialog.show("Push Notifications", "doSubscribeSuccess", [ {
        text : 'Close',
        handler : function() {}}
    ]);
}

 function doSubscribeFailure() {
    WL.SimpleDialog.show("Push Notifications", "doSubscribeFailure", [ {
        text : 'Close',
        handler : function() {}}
    ]);
}

//------------------------------- Unsubscribe ---------------------------------------
function doUnsubscribe() {
    WL.Client.Push.unsubscribe("myPush", {
        onSuccess: doUnsubscribeSuccess,
        onFailure: doUnsubscribeFailure
    });
}

function doUnsubscribeSuccess() {
    WL.SimpleDialog.show("Push Notifications", "doUnsubscribeSuccess", [ {
        text : 'Close',
        handler : function() {}}
    ]);
}

function doUnsubscribeFailure() {
    WL.SimpleDialog.show("Push Notifications", "doUnsubscribeFailure", [ {
        text : 'Close',
        handler : function() {}}
    ]);
}

//------------------------------- Handle received notification ---------------------------------------
function pushNotificationReceived(props, payload) {
    WL.SimpleDialog.show("Push Notifications", "Provider notification data: " + JSON.stringify(props), [ {
        text : 'Close',
        handler : function() {
            WL.SimpleDialog.show("Push Notifications", "Application notification data: " + JSON.stringify(payload), [ {
                text : 'Close',
                handler : function() {}}
            ]);     
        }}
    ]);
} 

И последний волшебный файл js обрабатывает аутентификацию на сервере МФУ.

var PushAppRealmChallengeHandler = (function(){

    var challengeHandler;

    function init() {
        challengeHandler = WL.Client.createChallengeHandler("PushAppRealm");
        challengeHandler.isCustomResponse = isCustomResponse;
        challengeHandler.handleChallenge = handleChallenge;
        challengeHandler.submitLoginFormCallback = submitLoginFormCallback;
    }

    function isCustomResponse(response) {
        if (!response || response.responseText === null) {
            return false;
        }
        var indicatorIdx = response.responseText.search('j_security_check');

        if (indicatorIdx >= 0){
            return true;
        }  
        return false;
    }

    function handleChallenge(response) {
        $('#AppBody').hide();
        $('#AuthBody').show();
        $('#passwordInputField').val('');
    }

    function submitLoginFormCallback(response) {
        var isLoginFormResponse = challengeHandler.isCustomResponse(response);
        if (isLoginFormResponse){
            challengeHandler.handleChallenge(response);
        } else {
            $('#AppBody').show();
            $('#AuthBody').hide();
            challengeHandler.submitSuccess();
        }
    }

    function submitLoginForm(url, options, callback) {
        challengeHandler.submitLoginForm(url, options, callback)
    }

    return {
        init: init,
        submitLoginForm: submitLoginForm,
        submitLoginFormCallback: submitLoginFormCallback
    }
})();

Я уже проверил сертификат, и все в порядке, также я переустанавливаю все, когда добавляю сертификат.

У вас есть идеи, где у меня могут быть проблемы? Когда следует вызывать onReadyToSubscribe? Связано ли это с аутентификацией приложения?

заранее спасибо


person m1sh0    schedule 19.07.2016    source источник
comment
Сегодня сообщалось о проблемах с токеном устройства из APN песочницы. Обратитесь к следующим ссылкам: 1) stackoverflow.com/questions/38453587/ 2) forums.developer.apple .com/message/155239#155239 3) forums.developer.apple.com/ поток/52224   -  person Vivin K    schedule 19.07.2016
comment
Попробуйте следующие подходы: а) Протестируйте с производственным сертификатом и производственными APN. б) Если это не сработает, протестируйте образец, доступный по адресу: github. .com/MobileFirst-Platform-Developer-Center/ Есть ли какая-то конкретная причина, по которой вы тестируете Eventsources? Для будущей совместимости вам следует использовать уведомления на основе тегов.   -  person Vivin K    schedule 19.07.2016
comment
Вы правы насчет проблемы, это было от Apple. Сегодня все работает как шарм. Спасибо.   -  person m1sh0    schedule 20.07.2016
comment
вам следует рассмотреть возможность использования подхода TagBased Notifications для ваших push-уведомлений. Уведомления об источниках событий больше не поддерживаются, начиная с MFPF 8.0. См. следующий блог: mobilefirstplatform.ibmcloud.com/blog/2016/04/05/   -  person Vivin K    schedule 20.07.2016


Ответы (1)


Это была проблема с точками доступа Apple Sandbox, которые не предоставляли токен, как указано в следующих ссылках:

https://forums.developer.apple.com/message/155239#155239

https://forums.developer.apple.com/thread/52224

person Vivin K    schedule 20.07.2016