Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
300 views
in Technique[技术] by (71.8m points)

iphone - How to get Target name?

We know that Xcode maintains environment variable of ${TARGET_NAME} but how to access this variable in objective-C code ?

What I have tried ?
I have added "TARGET_NAME=${TARGET_NAME}" this in Preprocessor macros section of Build Settings. But now I am not sure how to use this variable "TARGET_NAME" as a string in objective-C code.

In my case product name and target name are different so, no chance to use that.

I tried to access using

#ifdef TARGET_NAME
 NSLog(@"TargetIdentifier %@",TARGET_NAME);
#endif

This code is giving error like "Use of undeclared identifier 'myapptargetname'"

question from:https://stackoverflow.com/questions/18783055/how-to-get-target-name

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can add "TargetName" key to your Info.plist file:

enter image description here

Then you can access it (swift code):

var plistFileName = NSBundle.mainBundle().infoDictionary?["TargetName"] as String

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...