|
@@ -1,4 +1,4 @@
|
|
-import { _decorator, SpriteFrame, sys } from "cc";
|
|
|
|
|
|
+import { _decorator, error, SpriteFrame, sys } from "cc";
|
|
import { gameManager } from "./run/gameManager";
|
|
import { gameManager } from "./run/gameManager";
|
|
import { config } from "./config";
|
|
import { config } from "./config";
|
|
import { statisticsManager } from "./statisticsManager";
|
|
import { statisticsManager } from "./statisticsManager";
|
|
@@ -31,12 +31,15 @@ export class SdkUtil {
|
|
private static tt_totalRecord:number = 300; //抖音总录制时间
|
|
private static tt_totalRecord:number = 300; //抖音总录制时间
|
|
private static tt_isRecording:boolean = false; //抖音是否录制中
|
|
private static tt_isRecording:boolean = false; //抖音是否录制中
|
|
|
|
|
|
|
|
+ //------------------------------ 公共 ------------------------------//
|
|
|
|
+
|
|
public static init() {
|
|
public static init() {
|
|
this.ttGetSystemInfo(()=> {
|
|
this.ttGetSystemInfo(()=> {
|
|
- this.ttRegisterSidebar()
|
|
|
|
|
|
+ this.ttRegisterInfo()
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // 苹果手机是否有灵动岛
|
|
public static iPhoneIsLingdongdao():boolean {
|
|
public static iPhoneIsLingdongdao():boolean {
|
|
if(sys.platform==sys.Platform.BYTEDANCE_MINI_GAME) {
|
|
if(sys.platform==sys.Platform.BYTEDANCE_MINI_GAME) {
|
|
if(SdkUtil.tt_systemInfo !=null) {
|
|
if(SdkUtil.tt_systemInfo !=null) {
|
|
@@ -54,28 +57,18 @@ export class SdkUtil {
|
|
return false
|
|
return false
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * 自定义事件统计
|
|
|
|
- *
|
|
|
|
- * @param {string} eventType
|
|
|
|
- * @param {object} objParams
|
|
|
|
- */
|
|
|
|
|
|
+ // 自定义事件统计
|
|
public static customEventStatistics(eventType: string, objParams?: any) {
|
|
public static customEventStatistics(eventType: string, objParams?: any) {
|
|
eventType = eventType.toString();
|
|
eventType = eventType.toString();
|
|
- if (!objParams) {
|
|
|
|
- objParams = {};
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ if (!objParams) { objParams = {}; }
|
|
// console.log({'eventType': eventType},{'objParams': objParams});
|
|
// console.log({'eventType': eventType},{'objParams': objParams});
|
|
-
|
|
|
|
if (this.platform === 'wx') {
|
|
if (this.platform === 'wx') {
|
|
//@ts-ignore
|
|
//@ts-ignore
|
|
if (window['wx'] && window['wx']['aldSendEvent']) {
|
|
if (window['wx'] && window['wx']['aldSendEvent']) {
|
|
- //@ts-ignore
|
|
|
|
|
|
+ //@ts-ignore
|
|
window.wx['aldSendEvent'](eventType, objParams);
|
|
window.wx['aldSendEvent'](eventType, objParams);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
//@ts-ignore
|
|
//@ts-ignore
|
|
if (this.platform === 'cocos' && window.cocosAnalytics && window.cocosAnalytics.isInited()) {
|
|
if (this.platform === 'cocos' && window.cocosAnalytics && window.cocosAnalytics.isInited()) {
|
|
console.log("###统计", eventType, objParams);
|
|
console.log("###统计", eventType, objParams);
|
|
@@ -84,17 +77,17 @@ export class SdkUtil {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // 检测显示添加桌面
|
|
|
|
+ public static checkIsShowAddDesktop():boolean {
|
|
|
|
+ if(sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
|
|
|
|
+ if(SdkUtil.tt_systemInfo.appName=='Douyin' || SdkUtil.tt_systemInfo.appName=='douyin_lite') {
|
|
|
|
+ return true
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return false
|
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
|
- * 抖音/微信分享
|
|
|
|
- *
|
|
|
|
- * @static
|
|
|
|
- * @param {string} title
|
|
|
|
- * @param {string} imageUrl
|
|
|
|
- * @param {string} videoPath
|
|
|
|
- * @returns
|
|
|
|
- * @memberof SdkUtil
|
|
|
|
- */
|
|
|
|
|
|
+ // 分享游戏
|
|
public static shareGame(title: string, imageUrl: string, videoPath: string) {
|
|
public static shareGame(title: string, imageUrl: string, videoPath: string) {
|
|
if(sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
|
|
if(sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
|
|
if(videoPath!="") {
|
|
if(videoPath!="") {
|
|
@@ -106,78 +99,7 @@ export class SdkUtil {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * 微信分享
|
|
|
|
- *
|
|
|
|
- * @static
|
|
|
|
- * @param {string} title
|
|
|
|
- * @param {string} imageUrl
|
|
|
|
- * @returns
|
|
|
|
- * @memberof SdkUtil
|
|
|
|
- */
|
|
|
|
- public static wxShare(title: string, imageUrl: string) {
|
|
|
|
- // console.log('微信分享=',title, 'imageUrl=',imageUrl)
|
|
|
|
- wx.showShareMenu({
|
|
|
|
- withShareTicket: true,
|
|
|
|
- // shareAppMessage(可以删除):显示分享给好友选项,shareTimeline(可以删除):显示分享至朋友圈选项
|
|
|
|
- // 可以只开启前者。如果要开启后者,则两者必须都开启才能生效。
|
|
|
|
- // menus: ['shareAppMessage', 'shareTimeline'],
|
|
|
|
- menus: ['shareAppMessage'],
|
|
|
|
- complete: () => {}
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- // 主动分享
|
|
|
|
- wx.shareAppMessage({
|
|
|
|
- title: title,
|
|
|
|
- imageUrl: imageUrl
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- // 被动分享
|
|
|
|
- // wx.onShareAppMessage( () => {
|
|
|
|
- // return {
|
|
|
|
- // // 标题,不传则默认使用小游戏的名称
|
|
|
|
- // title: title,
|
|
|
|
- // // 转发链接所显示的图片,比例5:4,资源可以是本地或远程。不传则默认使用游戏截图。
|
|
|
|
- // imageUrl: imageUrl,
|
|
|
|
- // }
|
|
|
|
- // });
|
|
|
|
-
|
|
|
|
- //@ts-ignore
|
|
|
|
- // if (!window.wx) {
|
|
|
|
- // return;
|
|
|
|
- // }
|
|
|
|
- //
|
|
|
|
- //@ts-ignore
|
|
|
|
- // wx.showShareMenu({
|
|
|
|
- // withShareTicket: true,
|
|
|
|
- // complete: () => {
|
|
|
|
- // console.log('')
|
|
|
|
- // }
|
|
|
|
- // }
|
|
|
|
- //
|
|
|
|
- //@ts-ignore
|
|
|
|
- // if (wx.aldOnShareAppMessage) {
|
|
|
|
- // //@ts-ignore 被动分享
|
|
|
|
- // wx.aldOnShareAppMessage(function () {
|
|
|
|
- // // 用户点击了“转发”按钮
|
|
|
|
- // return {
|
|
|
|
- // title: title,
|
|
|
|
- // imageUrl: imageUrl,
|
|
|
|
-
|
|
|
|
- // };
|
|
|
|
- // });
|
|
|
|
- // } else {
|
|
|
|
- // //@ts-ignore
|
|
|
|
- // wx.onShareAppMessage(function () {
|
|
|
|
- // // 用户点击了“转发”按钮
|
|
|
|
- // return {
|
|
|
|
- // title: title,
|
|
|
|
- // imageUrl: imageUrl,
|
|
|
|
- // };
|
|
|
|
- // });
|
|
|
|
- // }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ // 获取广告id
|
|
public static getAdId(ad_type = config.AD_TYPE.UNKNOWN):string {
|
|
public static getAdId(ad_type = config.AD_TYPE.UNKNOWN):string {
|
|
let ad_id = ""
|
|
let ad_id = ""
|
|
if(sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
|
|
if(sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
|
|
@@ -212,15 +134,7 @@ export class SdkUtil {
|
|
return ad_id
|
|
return ad_id
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * 抖音/微信激励视频
|
|
|
|
- *
|
|
|
|
- * @static
|
|
|
|
- * @param {string} _adUnitId
|
|
|
|
- * @param {Function} call_back
|
|
|
|
- * @returns
|
|
|
|
- * @memberof SdkUtil
|
|
|
|
- */
|
|
|
|
|
|
+ // 显示激励视频广告
|
|
public static showVideoAd(_adUnitId: string, call_back) {
|
|
public static showVideoAd(_adUnitId: string, call_back) {
|
|
if(gameManager.isFreeAds()) {
|
|
if(gameManager.isFreeAds()) {
|
|
call_back({"isEnded":true})
|
|
call_back({"isEnded":true})
|
|
@@ -264,9 +178,30 @@ export class SdkUtil {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * 抖音获取系统信息
|
|
|
|
- */
|
|
|
|
|
|
+ //------------------------------ 微信相关 ------------------------------//
|
|
|
|
+
|
|
|
|
+ // 微信分享
|
|
|
|
+ public static wxShare(title: string, imageUrl: string) {
|
|
|
|
+ // console.log('微信分享=',title, 'imageUrl=',imageUrl)
|
|
|
|
+ wx.showShareMenu({
|
|
|
|
+ withShareTicket: true,
|
|
|
|
+ // shareAppMessage(可以删除):显示分享给好友选项,shareTimeline(可以删除):显示分享至朋友圈选项
|
|
|
|
+ // 可以只开启前者。如果要开启后者,则两者必须都开启才能生效。
|
|
|
|
+ // menus: ['shareAppMessage', 'shareTimeline'],
|
|
|
|
+ menus: ['shareAppMessage'],
|
|
|
|
+ complete: () => {}
|
|
|
|
+ });
|
|
|
|
+ // 主动分享
|
|
|
|
+ wx.shareAppMessage({
|
|
|
|
+ title: title,
|
|
|
|
+ imageUrl: imageUrl
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //------------------------------ 抖音相关 ------------------------------//
|
|
|
|
+
|
|
|
|
+ // 抖音获取系统信息
|
|
public static ttGetSystemInfo(callback) {
|
|
public static ttGetSystemInfo(callback) {
|
|
if(sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
|
|
if(sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
|
|
tt.getSystemInfo({
|
|
tt.getSystemInfo({
|
|
@@ -280,13 +215,51 @@ export class SdkUtil {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * 抖音侧边栏
|
|
|
|
- *
|
|
|
|
- * @static
|
|
|
|
- * @memberof SdkUtil
|
|
|
|
- */
|
|
|
|
- public static ttRegisterSidebar() {
|
|
|
|
|
|
+ // 抖音添加快捷键(目前仅支持:抖音(Douyin) 和 抖音极速版(douyin_lite))
|
|
|
|
+ public static ttAddShortcut(onSuccess:Function = null, onFail:Function = null) {
|
|
|
|
+ if(sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
|
|
|
|
+ if(SdkUtil.tt_systemInfo.appName=='Douyin'||SdkUtil.tt_systemInfo.appName=='douyin_lite') {
|
|
|
|
+ if(SdkUtil.tt_systemInfo.brand=='Apple') {
|
|
|
|
+ tt.addShortcut({
|
|
|
|
+ success() {
|
|
|
|
+ console.log("添加桌面成功");
|
|
|
|
+ onSuccess && onSuccess(null)
|
|
|
|
+ },
|
|
|
|
+ fail(err) {
|
|
|
|
+ console.log("添加桌面失败", err.errMsg);
|
|
|
|
+ onFail && onFail(err)
|
|
|
|
+ },
|
|
|
|
+ });
|
|
|
|
+ } else if(SdkUtil.tt_systemInfo.brand=='Android') {
|
|
|
|
+ // 检测只支持安卓
|
|
|
|
+ tt.checkShortcut({
|
|
|
|
+ success(res) {
|
|
|
|
+ console.log("检查快捷方式", res.status);
|
|
|
|
+ if(res.status.exist==false||res.status.needUpdate==true) {
|
|
|
|
+ tt.addShortcut({
|
|
|
|
+ success() {
|
|
|
|
+ console.log("添加桌面成功");
|
|
|
|
+ onSuccess && onSuccess(null)
|
|
|
|
+ },
|
|
|
|
+ fail(err) {
|
|
|
|
+ console.log("添加桌面失败", err.errMsg);
|
|
|
|
+ onFail && onFail(err)
|
|
|
|
+ },
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ fail(err) {
|
|
|
|
+ console.log("检查快捷方式失败", err.errMsg);
|
|
|
|
+ onFail && onFail(err)
|
|
|
|
+ },
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 抖音注册信息
|
|
|
|
+ public static ttRegisterInfo() {
|
|
if(sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
|
|
if(sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
|
|
tt.onShow((res) => {
|
|
tt.onShow((res) => {
|
|
console.log('tt.onShow =', res)
|
|
console.log('tt.onShow =', res)
|