我同意 Mattia 的观点,Xcode 可能是最好的选择,但是:接受挑战。
首先,让我们使用 UIKit 编译 CodeRunner。在 CodeRunner 首选项中,复制 Objective-C 语言并将其命名为“iOS”。我使用 Xcode 使用的命令(您可以在 Log Navigator 中找到)作为模板。这也是马蒂亚所说的。将编译标志设置为如下所示:
-arch i386 -fmessage-length=0 -std=c99 -fpascal-strings -O0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk -fexceptions -fasm-blocks -g -fvisibility=hidden -fobjc-abi-version=2 -fobjc-legacy-dispatch -mios-simulator-version-min=5.1 -framework Foundation -framework UIKit -F /Applications/Xcode.app /Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/System/Library/Frameworks
注意iPhoneSimulator5.1.sdk 路径和-mios-simulator-version-min=5.1 标志。您可能需要针对自己的系统和版本更改这些设置。
首先,请尝试使用以下 iOS 代码(您也可以在首选项中将此作为模板):
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface AppDelegate : NSObject <UIApplicationDelegate>
@property (nonatomic, retain) UIWindow * window;
@property (nonatomic, retain) UIViewController * viewController;
@end
@implementation AppDelegate
@synthesize window = _window;
@synthesize viewController = _viewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.viewController = [[[UIViewController alloc] initWithNibName:nil bundle:nil] autorelease];
self.viewController.view.backgroundColor = [UIColor orangeColor];
UILabel * label = [[UILabel alloc] initWithFrame:self.viewController.view.bounds];
label.font = [UIFont boldSystemFontOfSize:48.0];
label.textColor = [UIColor whiteColor];
label.backgroundColor = [UIColor clearColor];
label.textAlignment = UITextAlignmentCenter;
label.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
label.text = @"Hello World";
[self.viewController.view addSubview:label];
[label release];
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
@end
int main(int argc, char *argv[]) {
@autoreleasepool {
UIApplicationMain(argc, argv, nil, @"AppDelegate");
}
}
如果你尝试运行,它应该可以编译,但是应用程序会因为这个错误而崩溃:
dyld:库未加载:/System/Library/Frameworks/UIKit.framework/UIKit
这是因为您尝试在没有 UIKit 的 Mac 上运行 iOS 应用;它需要在模拟器中运行。返回首选项,将运行命令更改为:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app/Contents/MacOS/iPhone\ Simulator -SimulateApplication $PWD/$compiler
现在运行相同的代码。 iOS 模拟器应该会启动,您应该会看到一个带有“Hello World”的橙色屏幕:
现在让它与 SecureUDID 一起工作。您需要将代码保存在某处。现在将 SecureUDID .h 和 .m 文件复制到与保存的代码相同的文件夹中。将#import "SecureUDID.h"添加到文件顶部,将字体大小更改为14.0,将@"Hello World"更改为[SecureUDID UDIDForDomain:@"com.example.test" usingKey:@"abcdefg"]。如果您运行代码,它会抱怨找不到 SecureUDID 符号,正如您所看到的。我们需要将“SecureUDID.m”添加到编译标志中。因此,您可以在 CodeRunner 中重用 iOS 语言,您可以将其添加到自定义运行中的标志中,但是您每次要运行时都需要处理该模式视图。
你去吧:
很遗憾,日志不会出现在 CodeRunner 控制台中,但您可以打开 Mac 应用程序控制台来查看它们。我还得到了一些额外的黑色填充。还不知道我做错了什么。