我在 MobileFirst Platform 中有一个示例项目“调用适配器过程”。它在 MFP 控制台中预览时接收提要并显示值,但在添加 iPad 环境并在 Xcode 中运行它后,它不会获取任何提要,而是在 Xcode 控制台中显示错误:
无法获取 Feed
在 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 控制台日志
我使用了示例应用程序中给出的代码。