npm i --save nativescript-kiip
- 版本:0.1.3
- GitHub: https://github.com/sitefinitysteve/nativescript-kiip
- NPM: https://npmjs.net.cn/package/nativescript-kiip
- 下载
- 昨天: 0
- 上周: 0
- 上个月: 0
Nativescript Kiip 包装器
设置
将以下内容添加到 app.js 中,在 application.start 之前运行
if (application.ios) {
//iOS
var __extends = this.__extends || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
__.prototype = b.prototype;
d.prototype = new __();
};
var appDelegate = (function (_super) {
__extends(appDelegate, _super);
function appDelegate() {
_super.apply(this, arguments);
}
appDelegate.prototype.applicationDidFinishLaunchingWithOptions = function (app, launchOptions) {
kiip.initalize({
key: "<YOUR KEY>",
secret: "<YOUR SECRET>",
testMode: true
});
};
appDelegate.ObjCProtocols = [UIApplicationDelegate, KiipDelegate];
return appDelegate;
})(UIResponder);
application.ios.delegate = appDelegate;
}else{
//ANDROID
application.on(application.launchEvent, function (args) {
kiip.initalize({
key: "<YOUR KEY>",
secret: "<YOUR SECRET>",
testMode: true
});
});
}
iOS
看起来 kiip 使用 http,因此,在 iOS 中,我们需要根据指南在 info.plist 中允许 http
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
方法
var kiip = require("nativescript-kiip");
保存时刻
kiip.saveMoment({
id: "open_app"
}).then(function (args) {
if (args.poptart != null) {
if (app.android) {
var context = app.android.currentContext;
args.poptart.show(context); //<-- CRASH HERE
}else if(app.ios){
debugger;
args.poptart.show();
}
}
viewModel.debug = "Saved Moment " + new Date()
}, function (args) {
viewModel.debug = "Save Moment Failed";
});
选项
exports.onSetEmail = function (args) {
kiip.setEmail(viewModel.email);
}
exports.onSetBirthday = function (args) {
kiip.setBirthday(viewModel.birthday);
}
exports.onSetGender = function (args) {
kiip.setGender(viewModel.gender);
}
//iOS Only
exports.onStartSession = function (args) {
kiip.startSession().then(function (args) {
viewModel.debug = "Session Started " + new Date()
}, function (args) {
viewModel.debug = "Session Start Failed"
});
}
//iOS Only
exports.onEndSession = function (args) {
kiip.endSession().then(function (args) {
viewModel.debug = "Session Ended " + new Date()
}, function (args) {
viewModel.debug = "Session End Failed"
});
}