iOS main函数的一些知识,对于这个函数始终有一些神秘感,究其原因,我想大概他的那两个参数是脱不了干系的,于是我决定放手撕开一些的面纱,暴力处理一下:
for(inti =0; i <200; i ++) { printf(" %d argv = %s\n",i, argv[i]); }
而结果确实是,收获颇丰..
我得到了如下log
0 argv = /Users/Alesary/Library/Developer/CoreSimulator/Devices/F14599E0-C985-45CE-BBDB-BDE856C84A20/data/Containers/Bundle/Application/7ECAF1D6-4AB4-4CCD-AD99-B4C264FA71DD/main_demo.app/main_demo
1 argv = (null)
2 argv = DYLD_FRAMEWORK_PATH=/Users/Alesary/Desktop/testDemo/main_demo/Build/Products/Debug-iphonesimulator
3 argv = TMPDIR=/Users/Alesary/Library/Developer/CoreSimulator/Devices/F14599E0-C985-45CE-BBDB-BDE856C84A20/data/Containers/Data/Application/92E2F877-397A-4E40-80BE-184BA744D373/tmp
4 argv = SQLITE_ENABLE_THREAD_ASSERTIONS=1
5 argv = HOME=/Users/Alesary/Library/Developer/CoreSimulator/Devices/F14599E0-C985-45CE-BBDB-BDE856C84A20/data/Containers/Data/Application/92E2F877-397A-4E40-80BE-184BA744D373
6 argv = __XPC_DYLD_FRAMEWORK_PATH=/Users/Alesary/Desktop/testDemo/main_demo/Build/Products/Debug-iphonesimulator
7 argv = OS_ACTIVITY_DT_MODE=YES
8 argv = SIMULATOR_VERSION_INFO=CoreSimulator 518.22 - Device: iPhone 8 Plus - Runtime: iOS 11.4 (15F79) - DeviceType: iPhone 8 Plus
9 argv = SIMULATOR_UDID=F14599E0-C985-45CE-BBDB-BDE856C84A20
10 argv = SIMULATOR_MAINSCREEN_SCALE=3.000000
11 argv = SIMULATOR_EXTENDED_DISPLAY_PROPERTIES=/Users/Alesary/Library/Developer/CoreSimulator/Devices/F14599E0-C985-45CE-BBDB-BDE856C84A20/data/Library/Application Support/Simulator/extended_display.plist
12 argv = SIMULATOR_DEVICE_NAME=iPhone 8 Plus
13 argv = SIMULATOR_AUDIO_SETTINGS_PATH=/Users/Alesary/Library/Developer/CoreSimulator/Devices/F14599E0-C985-45CE-BBDB-BDE856C84A20/data/var/run/simulatoraudio/audiosettings.plist
14 argv = CFFIXED_USER_HOME=/Users/Alesary/Library/Developer/CoreSimulator/Devices/F14599E0-C985-45CE-BBDB-BDE856C84A20/data/Containers/Data/Application/92E2F877-397A-4E40-80BE-184BA744D373
15 argv = DYLD_FALLBACK_LIBRARY_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib
16 argv = SIMULATOR_RUNTIME_VERSION=11.4
17 argv = SIMULATOR_PRODUCT_CLASS=D21
18 argv = SIMULATOR_MODEL_IDENTIFIER=iPhone10,5
19 argv = SIMULATOR_MAINSCREEN_WIDTH=1242
20 argv = SIMULATOR_MAINSCREEN_PITCH=461.000000
21 argv = SIMULATOR_LEGACY_ASSET_SUFFIX=iphone
22 argv = SIMULATOR_CAPABILITIES=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/DeviceTypes/iPhone 8 Plus.simdevicetype/Contents/Resources/capabilities.plist
23 argv = SIMULATOR_BOOT_TIME=1535427993
24 argv = IPHONE_TVOUT_EXTENDED_PROPERTIES=/Users/Alesary/Library/Developer/CoreSimulator/Devices/F14599E0-C985-45CE-BBDB-BDE856C84A20/data/Library/Application Support/Simulator/extended_display.plist
25 argv = IPHONE_SHARED_RESOURCES_DIRECTORY=/Users/Alesary/Library/Developer/CoreSimulator/Devices/F14599E0-C985-45CE-BBDB-BDE856C84A20/data
26 argv = __XPC_DYLD_LIBRARY_PATH=/Users/Alesary/Desktop/testDemo/main_demo/Build/Products/Debug-iphonesimulator
27 argv = NSUnbufferedIO=YES
28 argv = CUPS_SERVER=/private/tmp/com.apple.launchd.s9zkYscz34/Listeners
29 argv = SIMULATOR_ROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot
30 argv = SIMULATOR_HOST_HOME=/Users/Alesary
31 argv = PATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/bin:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/bin:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/sbin:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/sbin:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/local/bin
32 argv = DYLD_ROOT_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot
33 argv = XPC_SERVICE_NAME=UIKitApplication:HL.main-demo[0xd90f][8044]
34 argv = DYLD_FALLBACK_FRAMEWORK_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks
35 argv = __XCODE_BUILT_PRODUCTS_DIR_PATHS=/Users/Alesary/Desktop/testDemo/main_demo/Build/Products/Debug-iphonesimulator
36 argv = RWI_LISTEN_SOCKET=/private/tmp/com.apple.launchd.3yrKAF0KIO/com.apple.webinspectord_sim.socket
37 argv = CLASSIC=0
38 argv = SIMULATOR_RUNTIME_BUILD_VERSION=15F79
39 argv = SIMULATOR_LOG_ROOT=/Users/Alesary/Library/Logs/CoreSimulator/F14599E0-C985-45CE-BBDB-BDE856C84A20
40 argv = SIMULATOR_AUDIO_DEVICES_PLIST_PATH=/Users/Alesary/Library/Developer/CoreSimulator/Devices/F14599E0-C985-45CE-BBDB-BDE856C84A20/data/var/run/com.apple.coresimulator.audio.plist
41 argv = IOS_SIMULATOR_SYSLOG_SOCKET=/private/tmp/com.apple.CoreSimulator.SimDevice.F14599E0-C985-45CE-BBDB-BDE856C84A20/syslogsock
42 argv = TESTMANAGERD_SIM_SOCK=/private/tmp/com.apple.launchd.0CuIZFdcpR/com.apple.testmanagerd.unix-domain.socket
43 argv = SIMULATOR_MEMORY_WARNINGS=/Users/Alesary/Library/Developer/CoreSimulator/Devices/F14599E0-C985-45CE-BBDB-BDE856C84A20/data/var/run/memory_warning_simulation
44 argv = SIMULATOR_MAINSCREEN_HEIGHT=2208
45 argv = SIMULATOR_HID_SYSTEM_MANAGER=/Library/Developer/PrivateFrameworks/CoreSimulator.framework/Resources/Platforms/iphoneos/Library/Frameworks/SimulatorHID.framework
46 argv = IPHONE_SIMULATOR_ROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot
47 argv = XPC_FLAGS=0x0
48 argv = DYLD_LIBRARY_PATH=/Users/Alesary/Desktop/testDemo/main_demo/Build/Products/Debug-iphonesimulator:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/system/introspection
49 argv = XPC_SIMULATOR_LAUNCHD_NAME=com.apple.CoreSimulator.SimDevice.F14599E0-C985-45CE-BBDB-BDE856C84A20
50 argv = SIMULATOR_SHARED_RESOURCES_DIRECTORY=/Users/Alesary/Library/Developer/CoreSimulator/Devices/F14599E0-C985-45CE-BBDB-BDE856C84A20/data
51 argv = (null)
52 argv = (null)
53 argv = executable_path=/Users/Alesary/Library/Developer/CoreSimulator/Devices/F14599E0-C985-45CE-BBDB-BDE856C84A20/data/Containers/Bundle/Application/7ECAF1D6-4AB4-4CCD-AD99-B4C264FA71DD/main_demo.app/main_demo
54 argv = pfz=0x7ffffff81000
55 argv = MallocNanoZone=1
56 argv =
57 argv =
58 argv = main_stack=
59 argv = executable_file=0x1801000004,0x201406737
60 argv = dyld_file=0x1801000004,0x2010b5e7d
61 argv = executable_cdhash=f49b276222e0b164e97b830d570534aac84424f4
62 argv = (null)