NativeScript for Mobile App Development Plugins and Native API Access 2 — Questions and Answers
Question 1: Which NativeScript plugin enables geolocation access?
- @nativescript/geolocation (Correct answer)
- nativescript-gps
- @nativescript/location
- ns-geolocation
Correct answer: @nativescript/geolocation
@nativescript/geolocation wraps the native location APIs on both iOS and Android, providing getCurrentLocation() and watchLocation() methods.
Question 2: How do you extend a native Android Activity in NativeScript?
- Use the android.app.Activity.extend() method to subclass it (Correct answer)
- Override the onCreate file in platforms/android
- Edit the MainActivity.java directly
- Use @AndroidActivity decorator
Correct answer: Use the android.app.Activity.extend() method to subclass it
NativeScript's extend() method allows JavaScript code to subclass native Java classes, enabling custom Activity behavior.
Question 3: What permission must be declared in AndroidManifest.xml to use internet access in NativeScript?
- android.permission.INTERNET (Correct answer)
- android.permission.NETWORK_ACCESS
- android.permission.WEB
- android.permission.CONNECT
Correct answer: android.permission.INTERNET
The INTERNET permission must be declared in the app's AndroidManifest.xml for any network requests to succeed on Android.
Question 4: Which NativeScript plugin enables push notifications via Firebase?
- @nativescript/firebase-messaging (Correct answer)
- @nativescript/push-notifications
- nativescript-fcm
- @nativescript/notifications
Correct answer: @nativescript/firebase-messaging
@nativescript/firebase-messaging integrates Firebase Cloud Messaging for push notifications on both iOS and Android.
Question 5: How does NativeScript handle iOS permissions (e.g., camera, location) for plugins?
- Plugins declare usage description strings in Info.plist; the OS prompts the user at runtime (Correct answer)
- Permissions are pre-granted during app install
- NativeScript requests all permissions at startup automatically
- Permissions are managed via a permissions.json file
Correct answer: Plugins declare usage description strings in Info.plist; the OS prompts the user at runtime
iOS requires NSCameraUsageDescription and similar keys in Info.plist; NativeScript plugins add these via their platforms/ios/Info.plist merge files.
Question 6: What does the `ns plugin add` command do?
- Installs a NativeScript plugin and runs its post-install scripts (Correct answer)
- Only downloads the plugin without installing
- Generates a plugin scaffold
- Updates an existing plugin
Correct answer: Installs a NativeScript plugin and runs its post-install scripts
`ns plugin add` is an alias for npm install that also runs plugin-specific post-install hooks to configure native project files.
Which NativeScript plugin enables geolocation access?