Separate package names for iOS and Android - nativescript

I currently have a native app published to the App Store and Google Play and both have different package names. I was wanting to know if there is there a way to tell NativeScript to use a one package name for iOS and a different one for Android? Thank you.

Yep, you can absolutely do that. For iOS, include a CFBundleIdentifier flag in your app/App_Resources/iOS/Info.plist file.
<key>CFBundleIdentifier</key>
<string>com.mycompany.myapp</string>
And for Android, update the android.defaultConfig.applicationId in your app/App_Resources/Android/app.gradle file. See https://github.com/NativeScript/template-hello-world/blob/90b81bcb772ab21a06f06bd502be2043e6afc9ee/App_Resources/Android/app.gradle#L11.

For those looking for a solution in 2021, there is an easy way to set it up.
Open your nativescript.config.ts and add different id properties inside android and ios:
import { NativeScriptConfig } from '#nativescript/core';
export default {
appPath: 'src',
appResourcesPath: 'App_Resources',
android: {
v8Flags: '--expose_gc',
markingMode: 'none',
id: 'com.yourapp.android'
},
ios: {
id: 'com.yourapp.ios'
}
} as NativeScriptConfig;

Related

How to programatically open Settings window in a macOS SwiftUI App

I have created a simple macOS-only SwiftUI app and added a Settings screen as per Apple's instructions:
import SwiftUI
#main
struct MyApp: App {
var body: some Scene {
WindowGroup {
RootView()
}
Settings {
SettingsView()
}
}
}
It works: the Preferences option shows up in the app menu. Now, I would also like to open this settings window programatically, e.g. when a button is clicked. Is there a way to achieve this?
I was hoping there would be a method in NSApplication, similar to the About window, but there doesn't seem to be one.
By inspecting the app menu, I found this solution:
NSApp.sendAction(Selector(("showPreferencesWindow:")), to: nil, from: nil)
I assume that it may not pass App Review for using a private API, though, so less shady alternatives are still welcome.
Update: This has actually passed App Review, so I'm marking it as the answer for now.
On macOS 13+ versions the action name has been renamed to Settings.
So to update Joshua's answer, here is the solution to use:
NSApp.sendAction(Selector(("showSettingsWindow:")), to: nil, from: nil)
I wonder if there is a settings scene id we can use with the new openWindow environment method. :)

Is it possible to build an Axway Appcelerator Android app with Product Flavors?

From my tiapp.xml file:
<ti:app xmlns:ti="http://ti.appcelerator.org">
<sdk-version>7.0.1.GA</sdk-version>
<id>com.example.app</id>
This will create and install an app with id com.example.app. But now I need to have installed, side-by-side a beta version. In theory I can change the id and do:
<id>com.example.app.beta</id>
And rebuild.
But I'm wondering if there's some kind of config, like we have with Gradle in Android so I can do:
android {
defaultConfig {
applicationId "com.example.app"
}
productFlavors {
beta {
applicationIdSuffix ".beta"
}
}
Any ideas? Thanks!
Have a look at this repo: https://github.com/yomybaby/dev.tiapp
It is an hook to change things in tiapp.xml
Also search for hook in the Appcelerator documentation to get more information about CLI-Hooks

Nativescript - platform specific code

I've got an iOS specific code (class definition) and would like to include in a separate ios specific file.
So I created two files
utils2.ios.ts <-- added my code here
utils2.android.ts
And then from another file, I did:
import utils2 = require("./utils2");
But I'm getting an error message that the module is not found.
I had to go this route because I've got a class definition in
the code and if I have just one file, I get a run-time error on Android.
Does typescript support platform specific files?
Or another option - is something like this possible in ts file
if ios
do this
end
Similar to C preprocesser
You can get by with just a utils.ts file and inside it you can do platform specific logic that you mention. Your issue about the module not found is likely just a path issue to that module, not that the module isn't actually there. Also note that Typescript doesn't really "support" platform specific files. Nativescript takes those .android.ts and .ios.ts files and at runtime loads the file you need on the platform running. So just FYI that's not really TS related :)
Nativescript provides a platform module in the tns-core-modules. Import the { isAndroid } or { isIOS } from the platform module in your code and use it as the
if (isAndroid) {
// do android only here
} else {
// ios
}

Unable To Share Text On Xamarin Form

Hello Everyone I want to share the Text on Xamarin Form using Library plugin.share. I have successfully implemented the library and on android i can able to share the text but in iOS it returns me nothing. i have done the share code on button click event so when i click on button in iOS its doesn't returns me anything.i tried the Below code but doesn't got succeed
CrossShare.Current.Share("Hii alll", "Share");
please help me to get out of this,thanks in advance
You want to take a look at UIActivityViewController, you can find the documentation here https://developer.xamarin.com/api/type/MonoTouch.UIKit.UIActivityViewController/
And Xamarin.Forms specific example http://devcenter.wintellect.com/jwood/implementing-sharing-in-xamarin-forms
This is a bit old, but I was having a similar issue and was able to resolve it.
First of all, you need to add the plugin Plugin.Share to ALL Xamarin.Forms projects (Portable, iOS, Android, UWP).
In the class that references the share code, add...
using Plugin.Share;
using Plugin.Share.Abstractions;
CrossShare.Share() doesn't work with strings, directly. You need to new up a ShareMessage.
var title = "Title For The Share";
var message = "Text to share.";
await CrossShare.Current.Share(new ShareMessage { Text = message, Title = title });
I can't say specifically to iOS, as I don't have a Mac and can't test that project, but Android and Windows 10 is working.

Appcelerator - Different xml for the same controller

Is possible to have one xml for iOS and one xml for Android for the same controller?
For example:
I have que controller: UIPhoto.js
and I want to have 2 different xml and tss files: UIPhoto-iOS.xml and UIPhoto-Android.xml
and charge each when the device is iOS or Android.
Thank you.
Yes it is possible and is quite simple!
You just need to have a different folder for the specific platform you want to target.
Imagine that you have the index.xml file inside Views folder, right?
You can code your xml as you're used to and if you want a different file for Android (let's say), you just need to create a folder inside "Views" folder called Android. Check this image with a folder structure:
Notice the Android folder in 'controllers' and the iOS in 'views' ;)
You may use platform specific folder in your views
controllers
--- UIPhoto.js
views
--- android
------ UIPhoto.xml
--- iOS
------ UIPhoto.xml
but i recommend you to use tss rather than use 2 xml and 2 tss.
for example in your tss:
"Window[platform=ios]":{
fullscreen : true
}
"View[platform=android]" :{
elevation : 8
}
"View[formFactor=tablet]" :{
elevation : 8
}
"View[platform=android formFactor=handheld]" :{
elevation : 8
}
and for your controller :
if(OS_IOS){
}
if(OS_ANDROID){
}
I don't think you can switch xml file or tss file when device is iOS or Android.
But maybe this is helpful:
First of all you can detect OS with Ti.Platform.osname; in your index.js and valorize a global varibale like this Alloy.Globals.OS.
Now you can switch your code with a simple if statements also in js file with:
if(Alloy.Globals.OS == "android"){...}
In your tss file you can distingue platform like this:
"#title[platform=android]" : {
font : { textStyle : Ti.UI.TEXT_STYLE_HEADLINE }
}

Resources