Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding launch argument for all targets

Tags:

xcode

ios

I am trying to disable OS_ACTIVITY_MODE for all targets in my project. The project has multiple targets. What I can do is to go to Edit Scheme->Arguments, and to add OS_ACTIVITY_MODE = disabled for specific action (run, archive etc) but only per target. How I would do the same for all targets at once for Run action (on a project level)?

like image 796
Whirlwind Avatar asked Mar 16 '21 13:03

Whirlwind


People also ask

What is a launch argument?

What is a launch argument. In programming, we can provide different inputs to a method by passing an argument. Launch argument is a way to pass arguments to the iOS application on launch. Launch Argument has many functions, but I will use a launch argument to set UserDefaults values.

How do you use launch arguments?

To enable launch arguments and set environment variables for your app, select your target from the Xcode toolbar and select “Edit Scheme…” On the left side of the panel, select “Run [AppName]. app”, and select the “Arguments” segment on the right side.

How do I add command line arguments in Xcode?

As of Xcode 4. x I've had to go to the Product menu, select "Edit Scheme", then select the arguments tab and add the arguments there. Also Option + clicking Run button will open this dialog.


Video Answer


1 Answers

The simplest solution is setting the environment variable programmatically with setenv on early start of your app i.e. in main.swift file. You can add main.swift to your project if you don't have one (you should remove @UIApplicationMain from your AppDelegate class).

//  main.swift

import Foundation
import UIKit

setenv("OS_ACTIVITY_MODE", "disable", 1)

UIApplicationMain(CommandLine.argc, CommandLine.unsafeArgv, nil, NSStringFromClass(AppDelegate.self))
like image 171
iUrii Avatar answered Oct 24 '22 05:10

iUrii