forked from github/jpush-phonegap-plugin
Improve example
This commit is contained in:
parent
291aa7b8bf
commit
8398bb56f1
@ -10,12 +10,11 @@
|
|||||||
<script type="text/javascript" src="cordova.js"></script>
|
<script type="text/javascript" src="cordova.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var onDeviceReady = function() {
|
var onDeviceReady = function() {
|
||||||
console.log("JPushPlugin:Device ready!");
|
|
||||||
initiateUI();
|
initiateUI();
|
||||||
};
|
};
|
||||||
|
|
||||||
var getRegistrationID = function() {
|
var getRegistrationID = function() {
|
||||||
window.plugins.jPushPlugin.getRegistrationID(onGetRegistrationID);
|
window.JPush.getRegistrationID(onGetRegistrationID);
|
||||||
};
|
};
|
||||||
|
|
||||||
var onGetRegistrationID = function(data) {
|
var onGetRegistrationID = function(data) {
|
||||||
@ -25,6 +24,7 @@
|
|||||||
if (data.length == 0) {
|
if (data.length == 0) {
|
||||||
var t1 = window.setTimeout(getRegistrationID, 1000);
|
var t1 = window.setTimeout(getRegistrationID, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#registrationId").html(data);
|
$("#registrationId").html(data);
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
console.log(exception);
|
console.log(exception);
|
||||||
@ -87,46 +87,95 @@
|
|||||||
|
|
||||||
var initiateUI = function() {
|
var initiateUI = function() {
|
||||||
try {
|
try {
|
||||||
window.plugins.jPushPlugin.init();
|
window.JPush.init();
|
||||||
window.setTimeout(getRegistrationID, 1000);
|
window.setTimeout(getRegistrationID, 1000);
|
||||||
if (device.platform != "Android") {
|
if (device.platform != "Android") {
|
||||||
window.plugins.jPushPlugin.setDebugModeFromIos();
|
window.JPush.setDebugModeFromIos();
|
||||||
window.plugins.jPushPlugin.setApplicationIconBadgeNumber(0);
|
window.JPush.setApplicationIconBadgeNumber(0);
|
||||||
} else {
|
} else {
|
||||||
window.plugins.jPushPlugin.setDebugMode(true);
|
window.JPush.setDebugMode(true);
|
||||||
window.plugins.jPushPlugin.setStatisticsOpen(true);
|
window.JPush.setStatisticsOpen(true);
|
||||||
}
|
}
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
console.log(exception);
|
console.log(exception);
|
||||||
}
|
}
|
||||||
$("#setTagWithAliasButton").click(function(ev) {
|
|
||||||
try {
|
|
||||||
var tag1 = $("#tagText1").attr("value");
|
|
||||||
var tag2 = $("#tagText2").attr("value");
|
|
||||||
var tag3 = $("#tagText3").attr("value");
|
|
||||||
var alias = $("#aliasText").attr("value");
|
|
||||||
var tags = [];
|
|
||||||
|
|
||||||
if (tag1 != "") {
|
$("#setTags").click(function(ev) {
|
||||||
tags.push(tag1);
|
try {
|
||||||
|
var tag1 = $("#tagText1").val()
|
||||||
|
var tag2 = $("#tagText2").val()
|
||||||
|
var tag3 = $("#tagText3").val()
|
||||||
|
var tags = []
|
||||||
|
|
||||||
|
if (tag1) {
|
||||||
|
tags.push(tag1)
|
||||||
}
|
}
|
||||||
if (tag2 != "") {
|
if (tag2) {
|
||||||
tags.push(tag2);
|
tags.push(tag2)
|
||||||
}
|
}
|
||||||
if (tag3 != "") {
|
if (tag3) {
|
||||||
tags.push(tag3);
|
tags.push(tag3)
|
||||||
}
|
}
|
||||||
window.plugins.jPushPlugin.setTagsWithAlias(tags, alias, function () {
|
|
||||||
// Success callback
|
window.JPush.setTags({ sequence: 1, tags: tags },
|
||||||
console.log(tags + ' - ' + alias)
|
(result) => {
|
||||||
});
|
$("#tagsResult").html(result.tags)
|
||||||
|
}, (error) => {
|
||||||
|
alert(error.errorCode)
|
||||||
|
})
|
||||||
} catch (exception) {
|
} catch (exception) {
|
||||||
console.log(exception);
|
console.log(exception)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
$("#getAllTags").click(function (event) {
|
||||||
|
window.JPush.getAllTags({ sequence: 2 },
|
||||||
|
(result) => {
|
||||||
|
$("#tagsResult").html(result.tags)
|
||||||
|
}, (error) => {
|
||||||
|
alert(error.errorCode)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
$("#cleanTags").click(function (event) {
|
||||||
|
window.JPush.cleanTags({ sequence: 2 },
|
||||||
|
(result) => {
|
||||||
|
alert(result.sequence)
|
||||||
|
$("#tagsResult").html("")
|
||||||
|
}, (error) => {
|
||||||
|
alert(error.errorCode)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
$("#setAlias").click(function (event) {
|
||||||
|
var alias = $("#aliasText").val()
|
||||||
|
window.JPush.setAlias({ sequence: 1, alias: alias },
|
||||||
|
(result) => {
|
||||||
|
$("#aliasResult").html(result.alias)
|
||||||
|
}, (error) => {
|
||||||
|
alert(error.errorCode)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
$("#getAlias").click(function (event) {
|
||||||
|
window.JPush.getAlias({ sequence: 2 },
|
||||||
|
(result) => {
|
||||||
|
alert(JSON.stringify(result));
|
||||||
|
}, (error) => {
|
||||||
|
alert(error.errorCode)
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#deleteAlias").click(function (event) {
|
||||||
|
window.JPush.deleteAlias({ sequence: 3 },
|
||||||
|
(result) => {
|
||||||
|
alert(JSON.stringify(result));
|
||||||
|
}, (error) => {
|
||||||
|
alert(error.errorCode)
|
||||||
|
})
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
document.addEventListener("jpush.setTagsWithAlias", onTagsWithAlias, false);
|
|
||||||
document.addEventListener("deviceready", onDeviceReady, false);
|
document.addEventListener("deviceready", onDeviceReady, false);
|
||||||
document.addEventListener("jpush.openNotification", onOpenNotification, false);
|
document.addEventListener("jpush.openNotification", onOpenNotification, false);
|
||||||
document.addEventListener("jpush.receiveNotification", onReceiveNotification, false);
|
document.addEventListener("jpush.receiveNotification", onReceiveNotification, false);
|
||||||
@ -176,13 +225,26 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div data-role="fieldcontain">
|
<div data-role="fieldcontain">
|
||||||
<input type="button" id="setTagWithAliasButton"
|
<input type="button" id="setTags" value="Set tags" />
|
||||||
value="Add tag and alias" />
|
<input type="button" id="getAllTags" value="Get all tags" />
|
||||||
|
<input type="button" id="cleanTags" value="Clean tags" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div data-role="fieldcontain">
|
||||||
|
<input type="button" id="setAlias" value="Set alias" />
|
||||||
|
<input type="button" id="getAlias" value="Get alias" />
|
||||||
|
<input type="button" id="deleteAlias" value="Delete alias" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div data-role="fieldcontain">
|
||||||
|
<label id="tagsPrompt">设置 Tag 的结果:</label>
|
||||||
|
<label id="tagsResult">null</label>
|
||||||
</div>
|
</div>
|
||||||
<div data-role="fieldcontain">
|
<div data-role="fieldcontain">
|
||||||
<label id="tagAliasPrompt">设置tag/alias结果:</label>
|
<label id="aliasPrompt">设置 Alias 的结果:</label>
|
||||||
<label id="tagAliasResult">null</label>
|
<label id="aliasResult">null</label>
|
||||||
</div>
|
</div>
|
||||||
<div data-role="fieldcontain">
|
<div data-role="fieldcontain">
|
||||||
<label id="notificationPrompt">接受的通知内容:</label>
|
<label id="notificationPrompt">接受的通知内容:</label>
|
||||||
@ -197,5 +259,4 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
Loading…
x
Reference in New Issue
Block a user