Open nickbr5 opened 7 years ago
Hey Juneil
Same here. I would love to see an example on how to use this plugin.
thanks!
Okay, got it by myself =)
Here's the hint for all the others struggling at the beginning:
I used the HelloWorld standard template for this.
Installing the plugin:
tns plugin add nativescript-kontaktio
Installing the geolocation plugin (in order to manage the permissions):
tns plugin add nativescript-geolocation
Run the app You'll get some errors. Have a look here for the solution. Run again and make sure the plugin throws no errors.
Using the plugin: I did my changes in item-detail.component.ts:
import { Component, OnInit } from "@angular/core";
import { ActivatedRoute } from "@angular/router";
import { Item } from "./item";
import { ItemService } from "./item.service";
import { Beacon } from "nativescript-kontaktio";
import { BeaconDiscover } from "nativescript-kontaktio";
@Component({
selector: "ns-details",
moduleId: module.id,
templateUrl: "./item-detail.component.html",
})
export class ItemDetailComponent implements OnInit {
item: Item;
BeaconDiscover: BeaconDiscover;
constructor(
private itemService: ItemService,
private route: ActivatedRoute,
) { }
ngOnInit(): void {
const id = +this.route.snapshot.params["id"];
this.item = this.itemService.getItem(id);
this.BeaconDiscover = new BeaconDiscover("PUT_YOUR_API_KEY_IN_HERE");
function beacon_callback(beacons: Beacon[]) {
for (let item of beacons) {
console.log(item.description);
console.log(item.uuid);
console.log(item.major);
console.log(item.minor);
}
}
this.BeaconDiscover.startListening("f7826da6-4fa2-4e98-8024-bc5b71e0893e");
this.BeaconDiscover.fetchBeacons(beacon_callback);**
}
}
I'm note sure if I've done it the "right way". But I get my beacons recognized.
@gitmiro I know it's been a while, but do you have any recent code of how to initialize this? This code doesn't work for me on android (#3)
Thank you
@mbouclas mh I still got the same codebase, but to be honest I haven't compiled the project since months. Can you share any errors?
I get this the moment i call the class this.BeaconDiscover = new BeaconDiscover('API_KEY');
Error: com.tns.NativeScriptException: Failed to find module: "nativescript-kontaktio", relative to: app/tns_modules/
com.tns.Module.resolvePathHelper(Module.java:146)
com.tns.Module.resolvePath(Module.java:55)
com.tns.Runtime.runModule(Native Method)
com.tns.Runtime.runModule(Runtime.java:553)
com.tns.Runtime.run(Runtime.java:545)
com.tns.NativeScriptApplication.onCreate(NativeScriptApplication.java:21)
android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1123)
android.app.ActivityThread.handleBindApplication(ActivityThread.java:6461)
android.app.ActivityThread.-wrap2(Unknown Source:0)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1969)
android.os.Handler.dispatchMessage(Handler.java:109)
android.os.Looper.loop(Looper.java:166)
android.app.ActivityThread.main(ActivityThread.java:7377)
java.lang.reflect.Method.invoke(Native Method)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:469)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:963)
File: "<unknown>, line: 1, column: 265
missed some of the errors
TypeError: Cannot read property 'create' of undefined
File: "file:///data/data/org.nativescript.preview/files/app/tns_modules/tns-core-modules/ui/builder/builder.js, line: 75, column: 14
StackTrace:
Frame: function:'', file:'file:///data/data/org.nativescript.preview/files/app/tns_modules/tns-core-modules/ui/builder/builder.js', line: 75, column: 15
Frame: function:'FrameBase.navigate', file:'file:///data/data/org.nativescript.preview/files/app/tns_modules/tns-core-modules/ui/frame/frame-common.js', line: 119, column: 30
Frame: function:'ActivityCallbacksImplementation.setActivityContent', file:'file:///data/data/org.nativescript.preview/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 863, column: 30
Frame: function:'ActivityCallbacksImplementation.onCreate', file:'file:///data/data/org.nativescript.preview/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 722, column: 14
Frame: function:'NativeScriptActivity.onCreate', file:'file:///data/data/org.nativescript.preview/files/app/tns_modules/tns-core-modules/ui/frame/activity.js', line: 20, column: 25
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3167)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3278)
at android.app.ActivityThread.-wrap12(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1894)
at android.os.Handler.dispatchMessage(Handler.java:109)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7377)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:469)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:963)
Caused by: com.tns.NativeScriptException:
Calling js method onCreate failed
Hi Juneil,
Nice job on the porting of Kontakt io to nativescript. I just started learning nativescript. Is it possible to provide an example of how to use your package?
Thank you