gpt4 book ai didi

ionic-framework - 如何将曲棍球应用程序与混合移动应用程序集成

转载 作者:行者123 更新时间:2023-12-04 07:13:31 24 4
gpt4 key购买 nike

我正在尝试将我的混合移动应用程序(Inonic + Cordova)与hockey App 集成但问题是 Hockey App 支持 native 应用程序(根据我的信息)。那么有没有可用的指南?混合应用与 Hockey 应用的集成

当我尝试跟踪 hockey 应用程序与 android 平台(混合应用程序)的集成时,它还告诉我要在主要事件中添加一些代码,以便我可以在哪里找到它

最佳答案

主要事件在 Android 平台内... cordova/platforms/android/src/...

在 onCreate 方法中放入 Register...

还有一些插件可以帮助完成这项任务,例如 https://github.com/peutetre/cordova-plugin-hockeyapp

考虑到很多 JavaScript 崩溃问题在原生世界中不会崩溃,这将有助于使用其他方式来传达受控错误,例如 saveException 方法,尝试通过插件将其暴露到 javascript 中,它将让存储上下文信息错误:http://hockeyapp.net/help/sdk/android/3.0.1/net/hockeyapp/android/ExceptionHandler.html

我已经在上述插件的分支中测试了仅适用于 Android 的解决方案: https://github.com/m-alcu/cordova-plugin-hockeyapp

有几个可用的操作,但您只需要使用“开始”和“saveException”来将受控错误发送到 hockeyapps。

曲棍球应用程序.js:

var exec = require('cordova/exec');

var hockeyapp = {
start:function(success, failure, token) {
exec(success, failure, "HockeyApp", "start", [ token ]);
},
feedback:function(success, failure) {
exec(success, failure, "HockeyApp", "feedback", []);
},
saveException:function(success, failure, description) {
exec(success, failure, "HockeyApp", "saveException", [ description ]);
}
};

module.exports = hockeyapp;

曲棍球应用程序.java:

package com.zengularity.cordova.hockeyapp;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONArray;
import android.widget.Toast;

import static net.hockeyapp.android.ExceptionHandler.saveException;
import net.hockeyapp.android.FeedbackManager;
import net.hockeyapp.android.CrashManager;
import net.hockeyapp.android.CrashManagerListener;

public class HockeyApp extends CordovaPlugin {

public static boolean initialized = false;
public static String token;
public static String description;

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
if (action.equals("start")) {
token = args.optString(0);
CrashManager.register(cordova.getActivity(), token, null);
initialized = true;
callbackContext.success();
return true;
} else if(action.equals("feedback")) {
token = args.optString(0);
FeedbackManager.register(cordova.getActivity(), token, null);
cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
FeedbackManager.showFeedbackActivity(cordova.getActivity());
}
});
callbackContext.success();
return true;

} else if(action.equals("saveException")) {
description = args.optString(0);
if(initialized) {

Toast toast = Toast.makeText(cordova.getActivity(), "problem", Toast.LENGTH_SHORT);
toast.show();

cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Exception e = new Exception("Send problem");
saveException(e, new CrashManagerListener() {
public String getDescription() {
return description;
}
});
}
});
callbackContext.success();
return true;
} else {
callbackContext.error("cordova hockeyapp plugin not initialized, call start() first");
return false;
}
}
else {
return false;
}
}

}

在 hellowold 示例 (index.js) 中使用此插件的示例:

var app = {
// Application Constructor
initialize: function() {
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicitly call 'app.receivedEvent(...);'
onDeviceReady: function() {
app.receivedEvent('deviceready');
},
// Update DOM on a Received Event
receivedEvent: function(id) {
var parentElement = document.getElementById(id);
var listeningElement = parentElement.querySelector('.listening');
var receivedElement = parentElement.querySelector('.received');

listeningElement.setAttribute('style', 'display:none;');
receivedElement.setAttribute('style', 'display:block;');

console.log('Received Event: ' + id);

hockeyapp.start(
function() { alert('hockeyapp initialised'); },
function(msg) { alert(msg); },
'< your APP ID >');

hockeyapp.saveException(
function() { alert('hockeyapp saveException'); },
function(msg) { alert(msg); },
'Something wrong has happened: bla bla bla...');
}
};

app.initialize();

Hockey 将这些受控异常存储在应用程序的文件目录中,并要求在用户下次打开应用程序时发送:

enter image description here

enter image description here

关于ionic-framework - 如何将曲棍球应用程序与混合移动应用程序集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27632658/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com