[INFO] iPhone Device family: iphone
[INFO] iPhone SDK version: 5.0
[INFO] Projekt/1.0 (2.0.2.GA.2ff31a3)
I am building an iOS app in Appcelerator and in this app I want to create a CommonJS module for UI components that I add to the global variable and then use it in other commonJS modules.
My code is based upon this example:
http://developer.appcelerator.com/blog/2011/09/forging-titanium-episode-6-a-single-context-tabbed-application-template.html
I add it into app.js like this:
var globals = {};
globals.Components = require ('ui/Components');
I use it in other modules like this:
var button_right = new globals.Components.NavBarButton ();
Is this a good way of doing it?
From the docs:
There shall not be ANY global variables in a Titanium application shared across all modules. Any data a module or any objects exposed by a module require should be passed in during construction or initialization.
So, you preferably pass any other parameter on new object's initialization, something like:
var module = new Module(param);
Related
Im currently facing an issue with using a 3rd party authenticator for my xamarin forms app. The code to execute has to be done natively in the platform project. The issue im facing is how to get the information(successful login, token, email etc) from the ios/android native project to the shared project for me to access it and continue the application. Below is an example of how the code looks below in the ios native project.
var client = new Auth0Client(new Auth0ClientOptions
{
Domain = "example.us.auth0.com",
ClientId = "123456789"
});
var loginResult = await client.LoginAsync();
I am trying to access android's R object in NativeScript with Angular but I haven't had any success. The instructions here say to do it like this:
android.R.color.holo_purple
But when I try to import the android variable from the application module or the tns-core-modules/platform module I get an error that the R property on the android object is undefined. How do I get access to R?
you don't need to import android variable from application module. it is automatically available by default at runtime. to remove compile time error property doesn't exists just declare the variable named android to any.
for example.
declare var android:any;
export class AppComponent{
let holoPurple=android.R.color.holo_purple;
}
Couldn't get existing answers to work in latest nativescript / angular. I resolved it with the following:
Created a file App_Resources/Android/values/keys.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="key_name">xxxxxx</string>
</resources>
Import these
import * as app from 'tns-core-modules/application';
import * as utils from 'tns-core-modules/utils/utils';
then to grab the string
const context = app.android.context;
const res = context.getResources().getString(utils.ad.resources.getStringId('key_name'));
The android here is the main namespace for the Android SDK and not the android property from the application module.
See this StackOverflow answer for instruction on how to access the native SDK via TypeScript or use the instruction from the related documentation article
So I've tried to follow this
http://www.mokacoding.com/blog/setting-up-firebase-without-cocoapods/
And then this https://facebook.github.io/react-native/docs/linking-libraries-ios.html
Firebase SDK seems to be loaded, XCode says:
2017-06-18 19:35:49.969 myapp[2224]
[Firebase/Analytics][I-ACS005000] The AdSupport Framework is not
currently linked. Some features will not function properly. Learn more
at (stackoverflow forbids shorteners)
2017-06-18 19:35:49.971 myapp[2224]
[Firebase/Analytics][I-ACS023007] Firebase Analytics v.4001000 started
Then I'm getting a "Native module cannot be null" red screen after React Native loads.
XCode says:
2017-06-18 19:48:39.975 [info][tid:main][RCTCxxBridge.mm:184]
Initializing (parent: , executor: (null))
2017-06-18 19:48:39.980 [warn][tid:main][RCTBridge.m:114] Class
RCTCxxModule was not exported. Did you forget to use
RCT_EXPORT_MODULE()?
2017-06-18 19:48:39.994 [info][tid:main][RCTRootView.m:302] Running
application myapp ({
initialProps = {
};
rootTag = 1; })
2017-06-18 19:48:40.305 [error][tid:com.facebook.React.JavaScript]
Native module cannot be null.
Did anyone have better luck than me?
How can i using internal database for example (sqlite) for offline app in nativescript without using any plugin.
i'm searched every were how i can installed or used sqlite or other internal database for nativescript but i didn't have any answer.
Just like you would do with any code that you need to access the native APIs
e.g. (JavaScript) Android example
var query = "select sqlite_version() AS sqlite_version";
var db = android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(":memory:", null);
var cursor = db.rawQuery(query, null);
var sqliteVersion = "";
if (cursor.moveToNext()) {
sqliteVersion = cursor.getString(0);
console.log(sqliteVersion);
}
The API references for SQLite in Android here and that said you can now follow a basic Android database tutorial and implement it step by step in your NativeScript application using JavaScript or TypeScript
Still, the plugin could provide all that wrapped in a ready-to-go functionality so unless you are lacking something it will be easier to use the nativescript-sqlite and avoid writing native code for Android and then for iOS.
We are implementing a server for app distribution and we need restrict the access to the apps by:
mac address
ip
At the moment I have not found any module that can obtain this data from the device in nativescript, so i don't know if there's a plugin or how else can I achieve this.
In nativescript you can access native apis of device
so if there isn't any module/plugin for it you can use this option for accessing native apis.
https://docs.nativescript.org/core-concepts/accessing-native-apis-with-javascript
for example there is solution for mac adress here
in JAVA:
WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo wInfo = wifiManager.getConnectionInfo();
String mac = wInfo.getMacAddress();
we can write it in javascript like this:
first we should fine where is this getSystemService:
after searching in documentation of android we found:
getSystemService is in android.content.Context
for accessing context in nativescript http://docs.nativescript.org/cookbook/application
we can do:
import app = require("application");
app.android.context;
so let's write it in javascript:
we don't have types in javascript so we use var instead;
var context = android.content.Context;
var wifiManager = app.android.context.getSystemService(context.WIFI_SERVICE);
var wInfo = wifiManager.getConnectionInfo();
var mac = wInfo.getMacAddress();
NOTE1 : as mentioned in above java solution link you should add this permision <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission> to app/App_Resources/AndroidManifest
NOTE2 : the above solution was for android,for ios you should find the solution with objective_c and convert to javascript with help of nativescript documentation.
NOTE3:In android 6 you might need request permision
You can also use this method to create a plugin for nativescript.