Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions demo/app/main-view-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ export class HelloWorldModel extends observable.Observable {
stopAfterFirstRead: true,
scanHint: "Scan a tag, baby!"
})
.then(() => this.set("lastNdefDiscovered", "Listening..."))
.catch(err => alert(err));
.then(() => this.set("lastNdefDiscovered", "Listening..."))
.catch(err => alert(err));
}

public doStopNdefListener() {
Expand All @@ -84,6 +84,8 @@ export class HelloWorldModel extends observable.Observable {
text: "Hello!"
}
]
}, (err) => {
this.set("lastNdefDiscovered", "Error " + err);
}).then(() => {
this.set("lastNdefDiscovered", "Wrote text 'Hello!'");
}, (err) => {
Expand All @@ -99,6 +101,8 @@ export class HelloWorldModel extends observable.Observable {
uri: "https://www.telerik.com"
}
]
}, (err) => {
this.set("lastNdefDiscovered", "Error " + err);
}).then(() => {
this.set("lastNdefDiscovered", "Wrote uri 'https://www.telerik.com");
}, (err) => {
Expand All @@ -107,8 +111,10 @@ export class HelloWorldModel extends observable.Observable {
}

public doEraseTag() {
this.nfc.eraseTag().then(() => {
this.set("lastNdefDiscovered", "Tag erased");
this.nfc.eraseTag((err) => {
this.set("lastNdefDiscovered", "Error " + err);
}).then(() => {
this.set("lastNdefDiscovered", "Erasing Tag");
}, (err) => {
console.log(err);
});
Expand Down
4 changes: 2 additions & 2 deletions src/nfc.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ export class Nfc implements NfcApi {
});
}

public eraseTag(): Promise<any> {
public eraseTag(callback: (data: any) => void): Promise<any> {
return new Promise((resolve, reject) => {
const intent = application.android.foregroundActivity.getIntent() || nfcIntentHandler.savedIntent;
if (!intent) {
Expand Down Expand Up @@ -371,7 +371,7 @@ export class Nfc implements NfcApi {
});
}

public writeTag(arg: WriteTagOptions): Promise<any> {
public writeTag(arg: WriteTagOptions, callback: (data: any) => void): Promise<any> {
return new Promise((resolve, reject) => {
try {
if (!arg) {
Expand Down
8 changes: 4 additions & 4 deletions src/nfc.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ export interface OnTagDiscoveredOptions {
export interface NfcApi {
available(): Promise<boolean>;
enabled(): Promise<boolean>;
writeTag(arg: WriteTagOptions): Promise<any>;
eraseTag(): Promise<any>;
writeTag(arg: WriteTagOptions, callback: (data: any) => void): Promise<any>;
eraseTag(callback: (data: any) => void): Promise<any>;
/**
* Set to null to remove the listener.
*/
Expand All @@ -113,7 +113,7 @@ export class Nfc implements NfcApi {
return undefined;
}

eraseTag(): Promise<any> {
eraseTag(callback: (data: any) => void): Promise<any> {
return undefined;
}

Expand All @@ -125,7 +125,7 @@ export class Nfc implements NfcApi {
return undefined;
}

writeTag(arg: WriteTagOptions): Promise<any> {
writeTag(arg: WriteTagOptions, callback: (data: any) => void): Promise<any> {
return undefined;
}
}
Loading