ios-sim: How to access command line arguments in m

2019-05-11 17:29发布

I am making use of the awesome ios-sim found on github.

It allows you to run the simulator via the command line and it also allows you to select which simulator (iphone or iPad) to use.

I am able to run my application flawlessly with it. However, I am unsure how to use the arguments passed to my application via the command line.

Has anyone done this or knows how to do this?

./ios-sim launch iTest.app --family ipad --args argument1 argument2

How do I access argument1 and argument2 in the iPhone application?

3条回答
我命由我不由天
2楼-- · 2019-05-11 17:50

in the main.m File you can print the arguments with:

int main(int argc, char *argv[])
{
 int i;
 for (i = 0; i < argc; i++) {
          NSLog(@"%s", argv[i]);
 }


@autoreleasepool {
...
...
    }
}
查看更多
劫难
3楼-- · 2019-05-11 17:57

You can use this to get the arguments:

[[NSProcessInfo processInfo] arguments];

I know this is an old question, but I thought I'd post it for future reference.

查看更多
做个烂人
4楼-- · 2019-05-11 18:03

iOS doesn't support command-line access. This is from Apple's Cocoa Fundamentals Guide, Page 17 http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaFundamentals/WhatIsCocoa/WhatIsCocoa.html#//apple_ref/doc/uid/TP40002974-CH3-SW27

Generally, the system libraries and frameworks of iOS that ultimately support UIKit are a subset of the libraries and frameworks in Mac OS X. For example, there is no Carbon application environment in iOS, there is no command-line access (the BSD environment in Darwin), there are no printing frameworks and services, and QuickTime is absent from the platform. However, because of the nature of the devices supported by iOS, there are some frameworks, both public and private, that are specific to iOS.

查看更多
登录 后发表回答