没有Xcode的生活的局限性
这实际上取决于你想要承受多少痛苦和做出多少妥协。基本上,如果没有Mac和Xcode,就无法进行AppStore的iOS开发。
没有Xcode的一些问题和例子
- 代码签名
codesign
- AppStore上传
- 库
UIKit
- 工具链
clang
这并不是说问题不能在某种程度上被克服,但它开始将您推向越狱的世界,而不是AppStore。因此,如果您仍然想为设备、模拟器和AppStore适当地开发,那么在没有Xcode项目的情况下,您可以做很多事情。
调试器和IDE的选择
您可以使用vi
或AppCode。任何文本编辑器都可以。您仍然需要在计算机上安装Xcode,以便具有编译器工具链和必要的库。真的无法避免这一点。然后,您可以在命令行中使用lldb
进行调试。通过ios-deploy来安装和管理应用程序。
一种排序的Hello World - 未命名.app
Github项目
我将为iPhone模拟器构建一个(极其)基本的应用程序。应用程序的基本习惯用语是具有.app
扩展名的文件夹,其中包含针对目标编译的Info.plist
和二进制文件。 Info.plist
包含显示名称、捆绑标识符和二进制名称。
Makefile
构建应用程序可能是最困难的部分。Makefile是不必要的,但它有助于保持您的理智。
default: main
.PHONY: clean
clean:
rm main
SYSROOT:=$(shell xcrun --sdk iphonesimulator --show-sdk-path)
main: main.m
clang -isysroot $(SYSROOT) -framework Foundation -framework UIKit -lobjc -o Untitled.app/$@ $<
Untitled.app文件夹和Info.plist
创建一个名为Untitled.app
的文件夹,并添加一个Info.plist
文件。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>Untitled</string>
<key>CFBundleExecutable</key>
<string>main</string>
<key>CFBundleIdentifier</key>
<string>com.cameronpalmer.Untitled</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Untitled</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
main.m
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(id)options {
NSLog(@"%s", __PRETTY_FUNCTION__);
CGRect mainScreenBounds = [[UIScreen mainScreen] bounds];
self.window = [[UIWindow alloc] initWithFrame:mainScreenBounds];
UIViewController *viewController = [[UIViewController alloc] init];
viewController.view.backgroundColor = [UIColor whiteColor];
viewController.view.frame = mainScreenBounds;
self.window.rootViewController = viewController;
[self.window makeKeyAndVisible];
return YES;
}
@end
int main(int argc, char *argv[]) {
NSLog(@"%s", __PRETTY_FUNCTION__);
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
在模拟器上构建和安装
# Build
make
# Boot
xcrun simctl boot <UUID_OF_DESIRED_SIMULATOR>
# Install
xcrun simctl install <UUID_OF_BOOTED_SIMULATOR> ./Untitled.app
# Open Simulator app
XCODE_PATH=$( xcode-select --print-path )
open "${XCODE_PATH}/Applications/Simulator.app"
现在只需启动应用程序,您将在模拟器中获得一个白色框。
xcodebuild
来构建怎么样? - Matej