Nativescript app crashes on adding nativescript-admob plugin - nativescript

I'm trying to add ads in my ng-nativescript app using nativescript-admob plugin.I'm following
this guide.I've done everything right but my app is crashing everytime.
here is app.component.ts
`
private androidBannerId: string = "ca-app-pub-kkkkkkkkk/tttttt";//replaced my own id
public createBanner() {
Admob.createBanner({
testing: true,
size: Admob.AD_SIZE.SMART_BANNER,
androidBannerId: this.androidBannerId,
margins: {
bottom: 0
}
}).then(function() {
console.log("admob createBanner done");
}, function(error) {
console.log("admob createBanner error: " + error);
});
}
public hideBanner() {
Admob.hideBanner().then(function() {
console.log("admob hideBanner done");
}, function(error) {
console.log("admob hideBanner error: " + error);
});
}
`
I've updated AndroidManifest.xml as mentioned in guide post.also I'm using nativescript-firebase
plugin by eddy verbruggen.Please help me here.

Related

AngularFireAuth signInWithEmailAndPassword callback is never thrown when deploying for iOS using Ionic Capacitor

I built a webapp using Ionic 3, Angular 12, Firebase 9, AngularFire.
When I try to authenticate (on iOS) the callback is never thrown from this function and therefore the authentication is never performed although the requests are executed with a status code of 200. On the web the authentication works as intended.
import { AngularFireAuth } from "#angular/fire/compat/auth";
...
async loginWithEmail(email: string, password: string) : Promise<void> {
return new Promise<User>((resolve, reject) =>
this.afAuth.signInWithEmailAndPassword(email, password).then(
(res) => {
resolve(res.user);
},
(error: { message: string }) => {
reject(error);
this.toastService.present({
message: "Something has gone wrong. Please try again.",
duration: 3000,
color: "warning"
});
console.error(error.message);
}
)
).then(
(result: User) => {
if (result) {
this._user.next(result);
} else {
if (result != null) {
this.zone.run(() => {
void this.router.navigate(['tabs', 'home']);
});
}
}
},
(error: { message: string }) => {
this.toastService.present({
message: error.message,
duration: 3000,
color: "warning"
});
}
);
}
What can I do about this behaviour?

OAuth2 Plugin to login using refresh tokens

I have a mobile application where I am trying to authenticate the user using the nativescript-oauth2 plugin with custom providers using Azure B2C. My requirement is that I want to make the user login for the first time to the application using their credentials. After the user has successfully logged in, I need to store the refresh token of the user and use these stored refresh token for authentication when next time the user is logging in to the mobile application. Using the refresh tokens, I want to generate all the tokens again.
I have tried using the refreshTokenWithCompletion() method provided by the plugin but as the document states that this is for refreshing the access tokens(OAuth 2 Plugin for NativeScript).
I too have an issue with fetching fresh token results using "refreshTokenWithCompletion".
below is my code
import { TnsOAuthClient, ITnsOAuthTokenResult, configureTnsOAuth } from 'nativescript-oauth2';
import { AuthProvider } from './auth-provider.service';
import { TnsOaUnsafeProviderOptions } from 'nativescript-oauth2/providers/providers';
#Injectable({
providedIn: 'root'
})
export class AuthService {
private client: TnsOAuthClient = null;
private customProvider: AuthProvider = null;
private customProviderOptions: TnsOaUnsafeProviderOptions = {
openIdSupport: "oid-none",
clientId: "",
redirectUri: "https://b2clogin.com/te/XXXXXXXXXXXXXX/XXXXXX_XXXXX_XXXXX/oauth2/authresp",
scopes: ["openid https://XXXXXXXXXXXXXX.onmicrosoft.com/mobileapi/user_impersonation offline_access"],
clientSecret: "",
customQueryParams: {
"p": "XXXXXX_XXXXX_XXXXX",
"nonce": "defaultNonce",
"response_mode": "query",
"prompt": "login"
}
};
constructor() {
this.customProvider = new AuthProvider(this.customProviderOptions);
configureTnsOAuth([this.customProvider]);
}
public Login(providerType): Promise<ITnsOAuthTokenResult> {
console.log('In Login');
this.client = new TnsOAuthClient(providerType);
return new Promise<ITnsOAuthTokenResult>((resolve, reject) => {
this.client.loginWithCompletion((tokenResult: ITnsOAuthTokenResult, error) => {
if (error) {
console.error("back to main page with error: ");
console.error(error);
// reject(error);
} else {
console.log("back to main page with access token: ");
console.log(tokenResult);
// resolve(tokenResult);
}
});
});
}
public Logout(): Promise<any> {
return new Promise<any>((resolve, reject) => {
if (this.client) {
this.client.logoutWithCompletion((error) => {
if (error) {
console.error("back to main page with error: ");
console.error(error);
reject(error);
} else {
console.log("back to main page with success");
resolve();
}
});
}
else {
console.log("back to main page with success");
resolve();
}
});
}
public RefreshAccess() {
this.client.refreshTokenWithCompletion((tokenResult: ITnsOAuthTokenResult, error) => {
if (error) {
console.error("Unable to refresh token with error: ");
console.error(error);
} else {
console.log("Successfully refreshed access token: ");
console.log(tokenResult);
}
});
}
}
Please let me know if there is any correction,
Error: Uncaught (in promise): URIError: URI malformed
I am using Azure AD B2C for identity management.

My app crashes on Android back button tap when the app is opened from nativescript-plugin-firebase notification message

I am working on a nativescript-angular application that receives [nativescript-plugin-firebase] notificatons.
The project is up to date. The package.json contains the following lines:
"tns-android": {
"version": "5.4.0"
},
"tns-core-modules": "~5.4.0",
"#angular/core": "~8.0.0"
"nativescript-plugin-firebase": "^9.0.1"
The notifications are fine but the app crashes when tapping the notification message if:
the app is opened (in foreground)
the device is closed
then tap the lock screen notification message
the app crashes
and displays:
An uncaught Exception occurred on 'main' thread.
java.lang.RuntimeException: Unable to destroy activity
I have encounter the same error on Android Emulator and on devices having Android 7, 8 and 9.
Screen error here
And here is the notification code inside src\app\app.component.ts :
ngOnInit(): void {
/// *** Firebase Cloud Messaging ***
firebase.addOnMessageReceivedCallback(
(message) => {
const that = this;
let contentId: string = "";
if (message.foreground) {
/** If the app is already open, show a dialog message. **/
confirm({
title: message.title,
message: message.body,
okButtonText: "Open",
cancelButtonText: "Cancel"
}).then(function (result) {
// result argument is boolean
if (result) {
if (message.data.contentId) {
contentId = message.data.contentId;
if (parseInt(contentId) > 0) {
that.routerExtensions.navigate(["/car-detail/" + contentId], { clearHistory: false });
}
}
}
// console.log("Dialog result: " + result);
});
}
else {
/** Else if the message arrived when the app is in the background, this code is executed when the user taps on the notification. **/
if (message.data.contentId) {
contentId = message.data.contentId;
if (parseInt(contentId) > 0) {
this.routerExtensions.navigate(["/car-detail/" + contentId], { clearHistory: false });
}
}
}
}
)
if (this.authenticationService.FirebaseToken == undefined || this.authenticationService.FirebaseToken == null) {
firebase.init({
// Optionally pass in properties for database, authentication and cloud messaging, see their respective docs.
onPushTokenReceivedCallback: function (token: any) {
console.log("Firebase push token: " + token);
}
, showNotificationsWhenInForeground: true
}).then(
() => {
console.log("firebase.init done");
},
error => {
console.log(`firebase.init error: ${error}`);
}
);
firebase.getCurrentPushToken().then((token: string) => {
// may be null if not known yet
console.log(`Current push token: ${token}`);
this.authenticationService.FirebaseToken = token;
});
}
// *** / Firebase Cloud Messaging ***
}

goolge api error { domain: 'androidpublisher', reason: 'noApks', message: 'This app has no APKs.' }

I followed the link here http://frontendcollisionblog.com/javascript/2015/12/26/using-nodejs-to-upload-app-to-google-play.html to use node to upload apk to googleapi. I always got this error
errors:
[ { domain: 'androidpublisher',
reason: 'noApks',
message: 'This app has no APKs.' } ]
This is my upload function
function upload(data) {
var edit = data.edit;
var apk = data.apk;
console.log("upload" + edit.data.id);
return new Promise(function(resolve, reject) {
play.edits.apks.upload({
editId: edit.data.id,
media: {
mimeType: 'application/vnd.android.package-archive',
body: apk
}
}, function(err, res) {
if(err || !res) {
reject(err);
}
resolve(_.omit(_.extend(data, { uploadResults: res }), 'apk'));
});
});
}
Anyone know what the error is and how to fix it?

Parameter in $stateParams are undefined in resolve

I have a page showing a list of contact and clicking on one of the contacts in the view should switch to detail state as below:
dashboard-contacts-controller.js
vm.viewContact = function(contactId) {
console.log("Load contact " + contactId);
$state.go("app.dashboards_contact", {"id": contactId});
}
contacts-module.js
.state('app.dashboards_contact', {
url: '/dashboard-contact/:id',
views: {
'content#app': {
templateUrl: 'app/main/apps/dashboards/contacts/about/about.html',
controller: 'DashboardContactController as vm'
}
},
resolve: {
contact: ['DashboardContactsDataService', function($stateParams, DashboardContactsDataService) {
console.log($stateParams.id);
return DashboardContactsDataService.get($stateParams.id);
}
]
},
bodyClass: 'dashboard-contact'
});
$stateParams.id in resolve is always undefined.
You didnt inject $stateParams in resolve. Shouldn't it be
resolve: {
contact: ['$stateParams', DashboardContactsDataService', function($stateParams, DashboardContactsDataService) {
console.log($stateParams.id);
return DashboardContactsDataService.get($stateParams.id);
}
]
},

Resources