Get additional geolocation data (GnssStatus) in NativeScript application - geolocation

In my NativeScript app I need to get additional geolocation info like satellite count or satellite ids which isn't provided by nativescript-geolocation plugin.
I am trying to use GnssStatus class from android.location in NativeScript app with the following:
const gnssCb = new android.location.GnssStatus.Callback();
After that I get an error:
ERROR Error: JNI Exception occurred (SIGABRT)
What am I doing wrong?
Or is there any alternative way I can get that info?

android.location.GnssStatus.Callback is a class inherited from Object, so you may have to extend it to override the methods. I tested below code with Playground, it executes as expected.
class MyGnssStatus extends android.location.GnssStatus.Callback {
constructor() {
super();
return global.__native(this);
}
onSatelliteStatusChanged(status) {
}
}

Related

react-native-firebase (v6): App is crashing on ios when using secondary app, works fine on Android

package.json-
"#react-native-firebase/app": "8.3.1",
"#react-native-firebase/auth": "8.3.3",
"#react-native-firebase/firestore": "7.5.3",
Initialisation-
export const initGuestChatConnection = async () => {
// DEFAULT app will always be there
if (firebase.apps.length < 2) {
await firebase.initializeApp(
GUEST_CHAT_FIREBASE_CONFIG,
GUEST_CHAT_FIREBASE_CONFIG.app_name
);
}
};
Wrapper method to get secondary app instance-
export const getGuestChatFirebaseInstance = () => {
return firebase.app(GUEST_CHAT_FIREBASE_CONFIG.app_name);
};
When we try to use auth (custom signin), we get following error-
Exception '*** -[__NSDictionaryM setObject:forKeyedSubscript:]: key cannot be nil' was thrown while invoking addAuthStateListener on target RNFBAuthModule with params (
"GUEST_CHAT"
)
Our signin method-
export const signInGuestChatFirebaseInstance = token => {
return getGuestChatFirebaseInstance()
.auth()
.signInWithCustomToken(token);
};
We thought that problem is with authentication, so we skipped it and tried to directly access Firestore (by modifying Firestore Rules) but then we started getting following error-
Exception 'FirebaseApp instance may not be nil. Use FirebaseApp.app() if you'd like to use the default FirebaseApp instance.' was thrown while invoking collectionOnSnapshot on target RNFBFirestoreCollectionModule with params (
"GUEST_CHAT",
This is working fine on Android. These methods are working on ios as well for DEFAULT Firebase app but for some reason it's crashing for secondary app.
Create iOS app for the secondary project in order to make it work. Since on adding iOS app it provides GoogleService-info.plist, so extract all config related info from GoogleService-info.plist and use it to create config for initialising second app. This will make secondary app work on iOS!

created a small framework but showing init error in swift

I am trying to create my first framework ,
What I am trying to do is, I have added one public method to read the config json (dictionary) from app level. So I need app to pass this config dictionary and read using framework.
I have add framework all correctly and then imported it in app and tried to create instance but getting following error
“ 'Platform' initializer is inaccessible due to 'internal' protection leve
“
Here. “Platform is framework name.
Here is the code in framwork side
import Foundation
public class Platform {
public init(){
}
public func readConfigFileFromApp(config:Dictionary<String, String>) {
print (config)
//Read the configfile from app and save it here for rest of the SDK use
}
}
On app side i tried this line
import UIKit
import Platform
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let platform = Platform() . **//Getting error 'Platform' initializer is inaccessible due to 'internal' protection level**
// Do any additional setup after loading the view.
}
}
please help

Mapbox Navigation, Rerouting Issue in iOS SDK

Navigation keeps on constantly rerouting after every route progress even though the user device location is on the same route. I thought Mapbox automatically handles rerouting only when the user leaves the current route. After I read this part of the documentation, I thought I needed to handle it manually.
Based on documentation, I used below code to handle rerouting manually but the code is deprecated.
func navigationViewController(_ navigationViewController: NavigationViewController, shouldRerouteFrom location: CLLocation) -> Bool {
return navigationViewController.routeController.userIsOnRoute(location)
}
So crash redirects me to this part of Mapbox SDK
#available(*, deprecated, renamed: "navigationService", message: "NavigationViewController no longer directly manages a RouteController. See MapboxNavigationService, which contains a protocol-bound reference to the RouteController, for more information.")
/// :nodoc: obsoleted
#objc public final var routeController: RouteController! {
get {
fatalError()
}
set {
fatalError()
}
}
but navigationService not containing userIsOnRoute function. Is there an alternative function I could use, or is this a bug?
This issue appears to be a bug. Base on #luugiathuy report if you just change SDK to below code if will fix everything, voice and rerouting problem
index 47d8132..bc44ed7 100644
--- a/ios/Pods/MapboxCoreNavigation/MapboxCoreNavigation/NavigationService.swift
+++b/ios/Pods/MapboxCoreNavigation/MapboxCoreNavigation/NavigationService.swift
## -127,7 +127,7 ## public protocol NavigationService: CLLocationManagerDelegate, RouterDataSo #objc(MBNavigationService)
public class MapboxNavigationService: NSObject, NavigationService, DefaultInterfaceFlag {
- typealias DefaultRouter = RouteController
+ typealias DefaultRouter = LegacyRouteController
/**
The default time interval before beginning simulation when the `.onPoorGPS` simulation
In MapboxNavigationService change RouteController to LegacyRouteController and everything will work as expected.
The issue is on for almost 4 months, modifying SDK is not good idea but this is and alternative solution until Mapbox fix this issue.

What is the best way to implement firebase crash report in iOS swift 3

Here incase of android firebase crash can be implemented in APPLICATION class like.. below example
(...here, if android app is crashed this overrriden method uncaughtException(Thread thread, Throwable e) is called where we report crash to firebase...)
So, I want to know if there is any better way to implement firebase crash in iOS swift 3 like this.
/** onCreate method of MainApplication.java */
#Override
public void onCreate() {
super.onCreate();
reportFirebaseCrash();
}
/** Report FirebaseCrash Exception if application crashed */
private void reportFirebaseCrash() {
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
#Override
public void uncaughtException(Thread thread, Throwable e) {
AppUtils.showLog(TAG, "reportFirebaseCrash");
FirebaseCrash.report(e);
}
});
}
Highly recommend you check out the Firebase docs — they're quite well done and should give you all the help you need to get started.
In particular, the simplest way to get up and running is to use the crash reporting pod:
pod 'Firebase/Crash'
Then you need to configure a FIRApp shared instance. Once that's set up (or if you have already), you need to configure your build system to upload crash reports. The docs link includes all the necessary details to do it, but tl;dr, you need to create a new Run Script build phase:
# Replace this with the GOOGLE_APP_ID from your GoogleService-Info.plist file
GOOGLE_APP_ID=1:my:app:id
# Replace the /Path/To/ServiceAccount.json with the path to the key you just downloaded
"${PODS_ROOT}"/FirebaseCrash/upload-sym "/Path/To/ServiceAccount.json"
Firebase also supports Bitcode in order to gather crash data from production users.

The Type initializer for 'Realms.Realm' threw an exception

I am trying to implement Realm on a smaller Xamarin/Mvvmcross/iOS/Droid project in order to test it's ability to replace SQLite.
I have it working well on the iOS project but am getting exceptions on the Droid project when attempting to call Realm.GetInstance();
The Type initializer for 'Realms.Realm' threw an exception
Inner Exception
System.Reflection.ReflectionTypeLoadException
The classes in the module cannot be loaded.
I have narrowed it what I believe is an issue with reflection if the MvvmCross setup occurs before the Realm dll is loaded.
For example if I call Realm.GetInstance() in any activity that inherits from MvxActivity or MvxAppCompatActivity (or anywhere in the Mvvmcross Setup / CreateApp process) the exception occurs.
If however I call var db = Realm.GetInstance() (& db.Close()) from a normal Droid Activity first, and then start the Mvx Setup process, by starting an MvxActivity, from the Droid Activity it works fine, and continues to work through the application lifecycle.
Likewise if I subclass Application and open a Realm instance in OnCreate() and close it Real will initialise anywhere else in the application.
sample code
//works
[Application]
public class CustomApplication : Application
{
public CustomApplication (IntPtr javaReference, JniHandleOwnership transfer) : base (javaReference, transfer)
{
}
public override void OnCreate ()
{
base.OnCreate ();
var db = Realm.GetInstance ();
db.Close ();
}
}
//does not work unless Realm.GetInstance() has already been called once
[Activity(Label = "View for FirstViewModel")]
public class FirstView : MvxActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.FirstView);
var db = Realm.GetInstance ();
db.Close ();
}
}
I've put a test project on github at https://github.com/vurtigo/TestRealm
This is an unfortunate mix-up between Realm and Xamarin Android.
The static constructor on the Realm class walks through all the assemblies in the current AppDomain to discover all the types that inherit from RealmObject. However, if at the time Xamarin Android builds Java binding code this will define a new System.Reflection.Emit.AssemblyBuilder assembly that will raise a TypeLoadException when its types are enumerated (see Bug 39679 - ReflectionTypeLoadException after some reflection stuff).
The workaround is to cause the Realm static constructor to be invoked before any of the MvvmCross code causes Xamarin Android to emit binding code. You can do that by accessing any of the static members on Realm such as ReferenceEquals or even by including it in a typeof(Realm) expression. I suppose MvxApplication.Initialize() is a good place to do it.
In any case, I have proposed a fix that will ignore AssemblyBuilder instances in general. The very next Realm release should include it and you'll be able to delete the workaround code as soon as you upgrade.

Resources