Platform address:
Kuaishou Open Platform
(Scroll to the bottom and follow the steps)
Kuaishou Mini Game Entry Guide:
Kuaishou Open Platform
Technical documentation:
Kuaishou Open Platform
1. Publish it as a WeChat mini-game;
Check laya.wxmin.js
2. Add channel judgment to the index file:
window.isKSGame$ = typeof KSGameGlobal != 'undefined';
3. Subcontract loading:
(1) Judgment of subcontracting channels:
/**
* 加载分包
* @param {*} packs
* @param {*} callback
*/
loadPackages$(packs, callback) {
if (!packs || packs.length == 0) {
callback && callback();
return;
}
if (window.isKSGame$) {
this.loadPacksKs$(packs, callback);
return;
}
callback && callback();
}
(2) Actual subcontracting code:
/**加载快手分包 */
loadPacksKs$(packs, callback) {
var vPack = packs.shift();
if (!vPack) {
callback && callback();
return;
}
this.loadSinglePackKs$(vPack, packs, callback);
}
loadSinglePackKs$(vPack, packs, callback) {
if (this.checkPackLoaded$(vPack, packs, callback)) return;
ks.loadSubpackage({
name: vPack, // name 可以填 name 或者 root
success: this.onLoadedSinglePack$.bind(this, vPack, packs, callback),
fail: function (res) {
console.log("分包加载失败!!!!!重新加载", res);
},
});
}
(3) Check the subcontracting progress:
/**
* Detection of subpackage loading completed
* @param {*} vPack
* @param {*} packs
* @param {*} callback
* @returns
*/
checkPackLoaded$(vPack, packs, callback) {
if (this.loadedPacks$.indexOf(vPack) > -1) {
console.log("loadSubpackage success again:" + vPack);
this.loadPackages$(packs, callback);
return true;
}
}
4. After packaging, add files to the project root directory:
Import this file into the game.js file:
Developer Tools: There is no writer, only the project administrator can upload the project. Developers can use the test account to test, and they can only test on real machines.
"appid": "kwai_game_test_appid",
Kuaishou mini game video ID, it is recommended to write it down:
ks.createRewardedVideoAd({ adUnitId: "2300001301_01"});
5. When mixing and packaging with Kuaishou, you need to check: laya.wxmini.js
6. Yes, not only the video ID, but also the ID of the interstitial advertisement should be written down:
7. Common advertising errors:
8. Determine the host app platform:
if (window.ks && ks.getSystemInfo) {
ks.getSystemInfo({
success: function (res) {
console.log("当前的宿主平台111",res);
console.log("当前的宿主平台222",res.host);
console.log("当前的宿主平台....",res.host.env);
if (res.host.env === "kuaishou") {
this._isKUAISHOU$ = true;
}else if(res.host.env === "nebula"){
this._isKUAISHOU$ = false;
}
this._isKUAISHOU$ ? console.log("快手app") : console.log("快手极速版");
}.bind(this),
})
}