ios - 未调用 IBM MFP onReadyToSubscribe 方法

标签 ios ibm-mobilefirst hybrid

我有一个使用 Angular 在 IBM MFP 7.1 上编写的 iOS 混合应用程序。目前我正在尝试使用推送通知,但代码从未进入 onReadyToSubscribe 方法。

我从文档中获取了有关推送通知的所有代码,但仍然存在问题。

我的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 文件是我们应该拥有魔法的地方

    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 文件处理 MFP 服务器上的身份验证

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? 与应用程序的身份验证有关吗?

提前致谢

最佳答案

这是 Apple Sandbox APNs 的一个问题,不提供 token ,如以下链接中所报告:

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

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

关于ios - 未调用 IBM MFP onReadyToSubscribe 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38464638/

相关文章:

android - 当从后台到前台而不是堆栈中的最后一个 Activity 时,根 Activity 被一次又一次地调用

ios - 删除 CGContextAddPath 之后的路径

ios - UIAlertView 处理文本字段

ios - AnyObject 可以被视为普通对象吗?如何?

android - 有没有办法在 Android 或 iOS 库中的 worklight connect 方法调用中指定超时?

android - 用于真实设备的 IBM Worklight SQL 适配器

html - 在 Windows Phone 8 的 cordova 应用程序中禁用用户缩放

azure - 有没有办法为azure云服务或azure VM创建混合连接?

ios - 将数据从自定义单元格(在 ViewController 上的表中)传递到 uiviewcontroller 本身 Swift 3 iOS

angularjs - 在 Angular 组件中使用 AngularJS 指令