我正在尝试在Android上实现OneSignal's Push Notification SDK,为了做到这一点,我需要Extend Application Class并在
OneSignal.startInit
方法中调用onCreate
。
我一直在关注文档和Android Extend Sample App
中发布的指南。这些都不起作用。
尝试构建Android Extend Sample App
会导致Java ID 0 not found
错误。
我也在探索export class AppComponent extends android.app.Application
到目前为止我没有运气的可能性。
任何提示都会非常感激!
答案 0 :(得分:4)
有两种方法可以实现这一目标,后者是复杂的
将以下内容放在main.ts
中@IBAction func exploreBtnAction(sender : UIButton!){
let vcScene = self.navigationController?.storyboard?.instantiateViewControllerWithIdentifier("viewControllerVC_ID") as! ViewController
vcScene.btnLabelTxt = "Study"
//or you can just access the button itself in the viewController and set the title
//By vcScene.yourBtn.setTitle("Study", forState: .Normal)
self.navigationController?.pushViewController(vcScene, animated: true)
}
在app文件夹中创建一个新的JavaScript文件 - 将其命名为application.android.js
var application = require("application");
application.on(application.launchEvent, function (args) {
if (args.android) {
// For Android applications
com.onesignal.OneSignal.startInit(application.android.context).init();
} else if (args.ios !== undefined) {
// For iOS applications, args.ios
}
});
修改var application = require("application");
var superProto = android.app.Application.prototype;
var Application = android.app.Application.extend("org.myApp.Application", {
onCreate: function () {
superProto.onCreate.call(this);
application.android.init(this);
com.onesignal.OneSignal.startInit(this).init();
}
});
文件夹
AndroidManifest.xml
文件中的应用程序条目
<application-name>app/App_Resources/Android/