I'm making an app that has two targets :
Premium
Lite
Basically in my architecture, only the json config file that determines which assets are displayed on a version is different.
So let's say the premium app should load "config.json" and the lite version should load "config-lite.json".
I only need this string but I'm completely lost among the techniques used to differentiate targets (often dev and prod).
My projet uses cocoa pods, should I (can I) use this to provide an environment variable ?
Do you do this using a plist file ? Or a preprocessor macro ?
Considering the update of this post, what is the workaround for preprocessor macros in swift ?
This (great) article seems to sum up very well what I need to do but the syntax of the preprocessor macros seem to no longer work, am I right ?
I'm sorry that I don't have code to provide, I'm just trying to establish a best practice that hopefully would help other developers !
Related
Currently, I got a task to explore google flatbuffers on iOS and OSX. I explored the documentation provided by Google.
Also found some libraries on Github on swift language like FlatBuffersSwift and others that implement the flatbuffers.
So, I have mainly two concerns on that
Will Apple approve my app if I used this in my iOS application?
Is it possible to create schema on runtime from JSON ? or we must manually create schemas (.fbs) and use flatc library for creating model binaries (like .swift) files.
Any help please
Thanks in advance
1) There's nothing in the Apple approval process that has to do with your choice of serialization library.
2) To get the benefits of this library, you want to create a schema and generate code for it ahead of compilation time. If your use case is so dynamic that you want to be able to do everything at runtime, you're probably better off with a good JSON library.
I have an IOS app which holds lot of Configuration settings to use the app and also this app is used in 5 warehouses, settings will be differ from one warehouse to another warehouse. So it becomes more painful for the users using this app.. Even ever they install the app then need to set the configuration settings.
So my problem is If i hardcode the settings value, it is very difficult to maintain the code for all the different warehouse. if i do small change in my app have to change in all of the 5 source code.. Even if i decide to maintain 1 code .. i have to change the setting value every time before setting the build.. It is more painful for me.
so my question is..
Is there any way to run a app and set values in configuration settings. And generate this setting app as a build ?? i don't know it will workout or not please share me some ideas..
If I understand correctly, you want to have 1 source code and there is possibility to create different Targets. Each target can have it's own configuration plist file and you can set also different preprocessor macros for each target.
How to use preprocesor macros you can see here: How can I differentiate between multiple targets in xcode at runtime
How to create targets you can see here: Add preprocessor macro to a target in xcode 6
One more possibility (besides targets) is to create a shared library and if you want to apply some configs after installation you can prompt user to download one from a server (for instance)
Yes, you can create different schemas.
For example, you can create an application for Development, Staging, Production.
You can have configurations in plist file and make it variable according to the schemas.
When your application opens it will take the values according to the schema with which it was built.
Follow this guide to create different schemas.
Also, you can integrate Fastlane to generate builds easily with different schemas with simple commands.
Yes you can have one app with different targets and schema. Then just google it there's many articles about.
I'm developing an iOS app with Swift 2 and, like most developers, I have a staging and a production environment, with different servers, URL and settings.
I'm looking for a way to quickly switch between the two configurations as I'm developing the app.
On Android I could use build types and flavors to solve this problem.
I've read a lot of guides around the web but all of them were in Obj-C and relied on the macro preprocessor and the #ifdef that was available in Obj-C but isn't in Swift.
There are no clear guides on how to do this in swift and, being a total beginner, I'm not even sure where to start looking.
To recap: what I'm looking for it's a way to switch between two configurations (ex 2 property list files) and to reference the settings contained in those configurations from my code, based on the build I've selected.
You can add a user defined setting in Target's settings with different values for each scheme (Debug, Release, Ad-Hoc, AppStore etc) and use the user defined variable in info.plist file (or as you call it configurations).
Check answer to this question. Although the question is specific to Facebook App Id setup, the answer applies to any generic setting.
Once you have correct data in info.plist you can directly use it in code.
I am finishing up my first application and researched some methods to make use of two targets in the same project. There are few functions that will reduce the free version and will add adbmob banner.
The various tutorials that follow, the one who worked to differentiate the targets was this:
How to get Target name?
I researched other ways to accomplish this task are old threads and could not make it work.
I tried to add in FREE_VERSION Precompiler macros and many errors occurred. I also tried to add FREE_VERSION in Other C flags within LLVM 5.1 - Custom Compiler flags.
I'm not sure if these methods still work, or if there are better. Does anyone have a more current way to accomplish this or can I use the method I quoted at the beginning of the topic?
You can use a Preprocessor macro to mask off code that should run only in one version or the other, and you can use User-Defined Build Settings to differentiate important fields in your app's property list. Just make sure you produce archives for each version while in the correct build scheme when you're submitting.
However, Apple is becoming less friendly to "upselling", so if your free version asks the user to consider downloading the paid version, it will likely be rejected (they will cite guideline 2.9). To avoid that, you can either make a single version which is free and upgrades with an In-App Purchase, or you can be careful to make sure that the free version doesn't push the user toward the paid version.
I'm developing an iOS SDK that integrates other SDKs (Facebook SDK 3.5, for example).
To prevent collisions and allow my customers to import those SDKs as well, I want to rename all of the classes/enums in my code (for example, rename FBSession to RDFBSession, etc).
Is there an easy way to do this instead of going class-by-class and using Xcode's rename feature?
Apple provide a command-line tool called tops(1) that is designed for scripting large-scale code refactoring (renaming C functions, Objective-C methods, classes, and other tokens):
tops -verbose replace "FBSession" with "RDFBSession" Sources/*.[hm]
If you have a lot of replacements, you can put all of the replace... commands into a file that you pass with the -scriptfile option. The man page has more information on the more complex commands/options (and examples).
Xcode also offers textual Search and Replace. This will be faster than individual refactors, but it is ultimately less automated. You can make the step by step refactoring faster by first minimizing the project to the relevant dependencies/sources (if possible).
However, renaming the declarations in a library will not alter the symbol names of its associated binary. If it is distributed with a binary, then renaming will just result in linker errors or (in some cases) runtime errors.
The best idea if you need to use a 3rd party library which your clients might also use is to simply inform them they need to link the library with their app, then publish the version(s) the current release supports so they know they have some extra testing if they go too far ahead with some libraries.
I think that a better approach than simply renaming your classes would be to download Facebook's open source code, rename the classes there and compile a new static library with a set of renamed header files. Then you can be sure that no collisions occur and that you're using symbols that you named yourself.
I must warn you though - working like this may make updating the SDK a nightmare regardless of how you tackle this specific issue.