【问题标题】:MobileFirst Platform adapter invocation fails in simulatorMobileFirst Platform 适配器调用在模拟器中失败
【发布时间】:2015-04-01 04:52:47
【问题描述】:

我在 MobileFirst Platform 中有一个示例项目“调用适配器过程”。它在 MFP 控制台中预览时接收提要并显示值,但在添加 iPad 环境并在 Xcode 中运行后,它不会获取任何提要,而是在 Xcode 控制台中显示错误:

无法获取供稿

在 iOS 模拟器中:

服务不可用

适配器代码

<displayName>RSSReader</displayName>
<description>RSSReader</description>
<connectivity>
    <connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
        <protocol>http</protocol>
        <domain>rss.cnn.com</domain>
        <port>80</port> 
        <connectionTimeoutInMilliseconds>30000</connectionTimeoutInMilliseconds>
        <socketTimeoutInMilliseconds>30000</socketTimeoutInMilliseconds>
        <maxConcurrentConnectionsPerNode>50</maxConcurrentConnectionsPerNode>           
        <!-- Following properties used by adapter's key manager for choosing specific certificate from key store  
        <sslCertificateAlias></sslCertificateAlias> 
        <sslCertificatePassword></sslCertificatePassword>
        -->     
    </connectionPolicy>
</connectivity>

<procedure name="getFeeds"/>
<procedure name="getFeedsFiltered"/>

JS 代码

var busyIndicator = null;

function wlCommonInit(){
busyIndicator = new WL.BusyIndicator();
loadFeeds();
}

function loadFeeds(){
busyIndicator.show();

/*
 * The REST API works with all adapters and external resources, and is supported on the following hybrid environments: 
 * iOS, Android, Windows Phone 8, Windows 8. 
 * If your application supports other hybrid environments, see the tutorial for MobileFirst 6.3.
 */
var resourceRequest = new WLResourceRequest("/adapters/RSSReader/getFeedsFiltered", WLResourceRequest.GET);
resourceRequest.setQueryParameter("params", "['technology']");
resourceRequest.send().then(
        loadFeedsSuccess,
        loadFeedsFailure
);
}


function loadFeedsSuccess(result){
WL.Logger.debug("Feed retrieve success");
busyIndicator.hide();
if (result.responseJSON.Items.length>0) 
    displayFeeds(result.responseJSON.Items);
else 
    loadFeedsFailure();
}

function loadFeedsFailure(result){
WL.Logger.error("Feed retrieve failure");
busyIndicator.hide();
WL.SimpleDialog.show("Engadget Reader", "Service not available. Try again later.", 
        [{
            text : 'Reload',
            handler : WL.Client.reloadApp 
        },
        {
            text: 'Close',
            handler : function() {}
        }]
    );
}

function displayFeeds(items){
var ul = $('#itemsList');
for (var i = 0; i < items.length; i++) {
    var li = $('<li/>').text(items[i].title);
    var pubDate = $('<div/>', {
        'class': 'pubDate'
    }).text(items[i].pubDate);

    li.append(pubDate);

    ul.append(li);
}

Xcode 控制台日志

我使用了示例应用程序中给出的代码。

【问题讨论】:

  • 使用您的适配器调用代码以及 Xcode 日志编辑问题。还要确保 iPad 设备与服务器连接到同一网络,否则会失败。
  • @Idan 我用适配器代码、js 代码和 xcode 日志编辑了问题。
  • 它在模拟器中工作但在设备中失败。再说一遍,该设备是否与 Worklight Server 连接到同一网络?
  • @Idan 是的,它使用相同的网络。
  • 当然必须部署...

标签: ios ibm-mobilefirst mobilefirst-adapters


【解决方案1】:

我无法重现此错误。
确保这些是您已采取的步骤:

  1. 将“在混合应用程序中调用适配器过程”sample project 导入 MobileFirst Platform Studio 7.0
  2. 右键单击适配器文件夹并选择运行方式 > 部署 MobileFirst Adapter
  3. 右键项目文件夹选择New > MobileFirst Environment,添加iPad环境
  4. 右键单击 iPad 文件夹并选择 Run As > Xcode project
  5. 在 Xcode 中单击运行

对我来说,按照上述步骤,我能够在 iOS 模拟器中成功运行示例应用程序 = 显示应用程序并检索了提要。

【讨论】:

  • 此部署过程是否需要任何外部服务器。
  • 如果您在 Eclipse 中使用开发服务器,它有一个嵌入式服务器。你不是问这个问题的人。请不要混淆问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多