Đến từ một ứng dụng kết hợp POV. Đây là một ví dụ về javascript, tôi có một chân trang Có sẵn Cập nhật trên menu chính của mình. Nếu có bản cập nhật (tức là số phiên bản của tôi trong tệp cấu hình ít hơn phiên bản được truy xuất, hãy hiển thị chân trang) Sau đó, điều này sẽ hướng người dùng đến cửa hàng ứng dụng / play, nơi người dùng có thể nhấp vào nút cập nhật.
Tôi cũng nhận được dữ liệu mới (tức là Ghi chú phát hành) và hiển thị chúng trong một phương thức khi đăng nhập nếu đây là lần đầu tiên trên phiên bản này.
Trên thiết bị Sẵn sàng, hãy đặt URL cửa hàng của bạn
if (device.platform == 'iOS')
storeURL = 'https:
else
storeURL = 'https:
Phương thức Cập nhật Có sẵn có thể được chạy thường xuyên nếu bạn muốn. Của tôi được chạy mỗi khi người dùng điều hướng đến màn hình chính.
function isUpdateAvailable() {
if (device.platform == 'iOS') {
$.ajax(storeURL, {
type: "GET",
cache: false,
dataType: 'json'
}).done(function (data) {
isUpdateAvailable_iOS(data.results[0]);
}).fail(function (jqXHR, textStatus, errorThrown) {
commsErrorHandler(jqXHR, textStatus, false);
});
} else {
$.ajax(storeURL, {
type: "GET",
cache: false
}).done(function (data) {
isUpdateAvailable_Android(data);
}).fail(function (jqXHR, textStatus, errorThrown) {
commsErrorHandler(jqXHR, textStatus, false);
});
}
}
Gọi lại iOS: Apple có một API nên rất dễ lấy
function isUpdateAvailable_iOS (data) {
var storeVersion = data.version;
var releaseNotes = data.releaseNotes;
var _storeV = parseInt(storeVersion.replace(/\./g, ''));
var _appV = parseInt(appVersion.substring(1).replace(/\./g, ''));
$('#ft-main-menu-btn').off();
if (_storeV > _appV) {
$('#ft-main-menu-btn').text('Update Available');
$('#ft-main-menu-btn').click(function () {
openStore();
});
} else {
$('#ft-main-menu-btn').html(' ');
settings.updateReleaseNotes('v' + storeVersion, releaseNotes);
}
}
Android Callback: PlayStore bạn phải tìm kiếm, vì bạn có thể thấy phiên bản này tương đối dễ lấy và có gì mới tôi lấy html thay vì văn bản vì cách này tôi có thể sử dụng định dạng của chúng (tức là các dòng mới, v.v.)
function isUpdateAvailable_Android(data) {
var html = $(data);
var storeVersion = html.find('div[itemprop=softwareVersion]').text().trim();
var releaseNotes = html.find('.whatsnew')[0].innerHTML;
var _storeV = parseInt(storeVersion.replace(/\./g, ''));
var _appV = parseInt(appVersion.substring(1).replace(/\./g, ''));
$('#ft-main-menu-btn').off();
if (_storeV > _appV) {
$('#ft-main-menu-btn').text('Update Available');
$('#ft-main-menu-btn').click(function () {
openStore();
});
} else {
$('#ft-main-menu-btn').html(' ');
settings.updateReleaseNotes('v' + storeVersion, releaseNotes);
}
}
Logic của cửa hàng mở là thẳng về phía trước, nhưng để hoàn thiện
function openStore() {
var url = 'https://itunes.apple.com/us/app/appname/idUniqueID';
if (device.platform != 'iOS')
url = 'https://play.google.com/store/apps/details?id=appid'
window.open(url, '_system')
}
Đảm bảo Cửa hàng Play và Cửa hàng ứng dụng đã được đưa vào Danh sách trắng:
<access origin="https://itunes.apple.com"/>
<access origin="https://play.google.com"/>