Where is "containerEnvironment" in CloudKit? (Sandbox vs Production indicator) - cloudkit

The ToString() method of
CKContainer.FromIdentifier("iCloud.com.My-Company").PrivateCloudDatabase
results in this string
<CKDatabase: 0x7ca335b0; databaseScope=Public,
container=<CKContainer: 0x7fd630c0;
containerID=<CKContainerID: 0x7ca33910;
containerIdentifier=iCloud.com.getvalid.CloudKitAtlas,
containerEnvironment="Sandbox">>>
I'm unable to locate "ContainerEnviornment" in any child or parent object.
Where is ContainerEnviornment located?
I want to have some custom logic behave one way in SandBox, another in Production.

The CloudKit container environment is determined at run-time using your app's com.apple.developer.icloud-container-environment entitlement.
There is no easy, built-in way to query this on any of the CloudKit objects.
If you'd like to browse your CloudKit data, you can use CloudKit Dashboard.
If you want to display some additional/different data in your debug builds, you can detect whether your app is a debug or release build, and condition your debug-only display on that.
For Swift:
Open your Target's Build Settings > Swift Compiler - Custom Flags.
Add "-DDEBUG" to the Debug section under "Other Swift Flags".
Then, surround your Debug-only code with:
#if DEBUG
// debug only code
#endif

Related

Conditional Statements for App Extensions

I am trying to add Today Widget to my app and it needs to access the same file the main iOS app accesses. But in this file there's code the widget doesn't need access but needs to stay in that file. Is there some type of conditional I can use that checks if it's building for the widget or anything else like that?
I want to be able to do something like how it is when checking for macCatalyst like:
#if !TODAY_EXTENSION
codeForMainApp()
#endIf
I found this answer that says to just update the your debug and release xcconfig file, but my only xcconfig file for release and debug are the ones for my CocoaPods. Is it safe to update this?

Flutter - how to create a framework where i can have Debug and Prod versions where debug version has some way to choose test environment

I need to create two different versions of the app.
- debug
-prod
for debug, version i need user to select the test environment before anything else begins. i need some way to know what environment user has selected and then load API endpoints config file accordingly.
what's the best way to handle this in flutter?
I have seen in some apps that for iOS, debug options are available in app settings under the standard iOS settings menu , select the app and then see those options in there.
You might want to use Flutter Flavours. As the name suggests, you can practically make flavours of the same app based on your need - debug, test, production etc. And not only API end-points, but you can also configure everything else such as app icon, different labels on the screen etc.
As suggested in this link, you can have different main.dart file for each flavour. You can read different configuration from JSON file (such as API end-point) and rest of your app will remain same. For example, see below :
This is another helpful link.

Turning Firebase Analytics on on Xcode

I am trying to test the implementation of my Firebase Analytics. In their documentation they state that:
Enable debug mode by passing the -FIRDebugEnabled argument to the
application. You can add this argument in the application’s Xcode
scheme. When debug mode is enabled via -FIRDebugEnabled, further
executions of the application will also be in debug mode. In order to
return to default mode, you must explicitly disable the debug mode
with the application argument -FIRDebugDisabled.
Unfortunately I do not understand where it is that I set this scheme. In Android this was easy. Help would be appreciated.
I have found the answer on this alternative page of Google:
https://firebase.google.com/docs/analytics/ios/start
In Xcode, select Product > Scheme > Edit scheme...
Select Run from the left menu.
Select the Arguments tab.
In the Arguments Passed On Launch section, add -FIRAnalyticsDebugEnabled.
I wish Google would stop releasing half baked products and documentation. Could save hundreds of thousands of hours worldwide
I tried editing scheme and adding parameters, https://firebase.google.com/docs/analytics/ios/start but it did not work for me. In addition, I added following code after configuring FirebaseApp, at AppDelegate, didFinishLaunchingWithOptions
FirebaseApp.configure()
Analytics.setAnalyticsCollectionEnabled(true)
and it worked for me. I hope it helps you too.
I think you should check console log on XCode. Because I will show log
To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see https://help.apple.com/xcode/mac/8.0/#/dev3ec8a1cb4)
Check again, if you don't:
Add key FirebaseCrashlyticsCollectionEnabled has value true in Info.plist
set key IS_ANALYTICS_ENABLED is true in GoogleService-Info.plist
Make sure file GoogleService-Info.plist add will all targets and save in root project

Create an App within an App

I am being presented with a very interesting project. The task that I must complete is to figure out a way to allow a partner to be involved in an app without giving up their source code. The code will be included in the main bundle of the app so it is not dynamically stored. The partner has a fully functional app that is needed to be ran in a window within the main app at the appropriate time. I know having the partners create a web app would be ideal so it is treated like a webpage but I am more concerned with codes that must be written natively in iOS.
My question is what is the best way to go about solving this? In theory it is like an App within an App. Is there a way if they gave up their .app file I can include this in the bundle and then run it when I catch a certain event? Should I have the partners create their code in a framework and then import into the shell project? What is the best way to approach this problem?
If your 2nd-party doesn't want to provide you with the source code, why doesn't he compile it to object code then let you simply link it to your app?
By the way, at least on official (non-jailbroken) iDevices, apps can't 'embed' or 'open' one another in such a way - you can open an app programmatically if 1. it's a separate app 2. it has a registered special URL associated to its bundle.
Is there a way if they gave up their .app file I can include this in
the bundle and then run it when I catch a certain event?
No, you'll want to have them create a library instead. You can then include that library in your project.
Creating a library is as simple as:
Choose File->New...->Project... in Xcode.
Select the "Cocoa Touch Static Library" project template.
Add your code.
Build.
The result is a static library that you can add to your application(s). The library will contain the compiled code that you added, but doesn't include the source code. The library developer should provide whatever header files are necessary to use the code in the library.
An App within an App is possible however it requires a common data framework that allows one app to reference the same data without confusing the the source of and destination of the data.
Such a framework allows one app to interact with another app referencing the same data.

Maintaining different URLs for different Build Configurations in xcode

I created four different build configurations to my xcode project, they are QA, STAGING< UAT<& PRODUCTION. I use 4 different urls each for one build i created.
Now my question is xcode 4 is very good at detecting DEBUG mode as there is already predefined macro available, but How can I detect my custom builds so that i can pass different urls for different builds configurations?
In each one of those build configurations go into build settings and add a #define THIS_IS_QA=1 then test for it in your code and use it as you would use the DEBUG macro
The preprocessor macro route works alright and is quick to implement. But it does not scale well since you will end up with copies of each variable. The route I find works the best is to do the following.
Define the configuration as a User-Defined Setting in the project or target build settings.
Doing this allows for different values to be specified for each build configuration (eg. Debug or Release or even a custom one)
Create an information property in the projects plist file.
This allows the build setting to be accessed through the plist.
Write the code once to load the value form the plist file.
Example:
In the project create a User-Defined Setting called "BASE_API_URL" and set the debug configuration to "http://www.test.example.com" and the release configuration to "http://www.example.com".
Then in the plist create a new information property with the key of "BaseAPIUrl" and the value of "$(BASE_API_URL)"
Lastly in the app delegate where you define the base url add the following code:
let baseUrl: NSString = NSBundle.mainBundle().infoDictionary?["BaseAPIUrl"]! as NSString