Xcode 10.3 ,10.1集成 Unity 2018.2.21f1

過程很簡(jiǎn)單,因?yàn)橹皩?duì)player setting的不清晰理解,導(dǎo)致折騰了兩天幾近才完成編譯!具體看導(dǎo)出ios工程一文。

player setting關(guān)鍵設(shè)置

工程集成和設(shè)置

步驟一


下面的一定要注意添加的方式是不同的

步驟二

在項(xiàng)目根目錄中新建PCH文件,然后將Classes下的Prefix.pch文件中的全部代碼復(fù)制到剛才創(chuàng)建的PCH文件中,并在代碼中添加#import "UnityAppController.h"

步驟三

將PCH文件的路徑添加到Target->Build Setting->Prefix Header中 (直接拖拽就可以自動(dòng)加載路徑了)

步驟四

在Target->Build Setting中進(jìn)行以下配置:

a.設(shè)置Enable Bitcode:NO;

b.Other Linker Flags添加(注意:一定要按順序)-weak_framework,CoreMotion,-weak-lSystem,-licucore

c.對(duì)Classes和Libraries的路徑進(jìn)行配置;

在Header Search Paths中添加:

$(SRCROOT)/Classes

$(SRCROOT)/Classes/Native

$(SRCROOT)/Libraries/libil2cpp/include

在Library Search Paths中添加:

$(PROJECT_DIR)/Libraries(如有,則不需要重復(fù)添加)

$(PROJECT_DIR)/Libraries/Plugins/iOS (這個(gè)因?yàn)槲矣貌坏剑虼丝床坏絧lugin文件夾)

d.Other C Flags添加 -DINIT_SCRIPTING_BACKEND=1 和 -DRUNTIME_IL2CPP=1

e.設(shè)置Enable C++ Runtime Types:NO

f.設(shè)置Overriding Deprecated Objective-C Methods:Yes

g.設(shè)置Unintentional Root Class:Yes

h.點(diǎn)擊如下圖的+號(hào),添加4個(gè)Add User-Defined Setting

GCC_THUMB_SUPPORT : NO

GCC_USE_INDIRECT_FUNCTION_CALLS : NO

UNITY_RUNTIME_VERSION : 2018.2.21f1(以自己Unity實(shí)際版本號(hào)為準(zhǔn))

UNITY_SCRIPTING_BACKEND : il2cpp

步驟五

在Target->Build Phases中導(dǎo)入以下庫(建議以自己Unity導(dǎo)出的Xcode項(xiàng)目對(duì)應(yīng)添加): 注意如果原來unity是optional選項(xiàng)的庫,也同樣設(shè)置為optional的。而且發(fā)現(xiàn)沒有l(wèi)ibiconv.2.dylib,就沒有管,暫時(shí)也沒有問題

步驟六

Classes文件夾下的main.mm中全部代碼復(fù)制到Xcode生成的main.m中;將main.mm代碼中的"UnityAppController"修改成"AppDelegate";

將main.m修改為main.mm然后刪除classes下的原來的main文件,不要remove to trash

步驟七

把Classes文件夾下的UnityAppController.h如下修改

#import "AppDelegate.h"
inlineUnityAppController* GetAppController()

{

? ? AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;

? ? returndelegate.unityVC;

? ? //return _UnityAppController;

}

步驟八

對(duì)AppDelegate進(jìn)行如下修改:


#import "AppDelegate.h"

#import "UnityAppController.h"

#import "ViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (UIWindow*)unityWindow {

? ? return UnityGetMainWindow();

}

- (void)showUnityWindow {

? ? [self.unityWindow makeKeyAndVisible];

? ? UIButton *back = [UIButton buttonWithType:UIButtonTypeSystem];

? ? back.frame=CGRectMake(80, 200, 80, 30);

? ? [self.unityWindow addSubview:back];

? ? [backsetTitle:@"goToiOS" forState:UIControlStateNormal];

? ? [backaddTarget:self action:@selector(hideUnityWindow) forControlEvents:UIControlEventTouchUpInside];

}

- (void)hideUnityWindow {

? ? [self.window makeKeyAndVisible];

}

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {

? ? // Override point for customization after application launch.

? ? self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

? ? self.window.backgroundColor = UIColor.redColor;

? ? self.unityVC = [[UnityAppController alloc] init];

? ? [self.unityVC application:application didFinishLaunchingWithOptions:launchOptions];

? ? ViewController *vc = [[ViewController alloc] init];

? ? self.window.rootViewController = vc;

? ? [self.window makeKeyAndVisible];

? ? return YES;

}

- (void)applicationWillResignActive:(UIApplication*)application {

? ? // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

? ? // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.

? ? [self.unityVC applicationWillResignActive:application];

}

- (void)applicationDidEnterBackground:(UIApplication*)application {

? ? // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.

? ? // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

? ? [self.unityVC applicationDidEnterBackground:application];

}

- (void)applicationWillEnterForeground:(UIApplication*)application {

? ? // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.

? ? [self.unityVC applicationWillEnterForeground:application];

}

- (void)applicationDidBecomeActive:(UIApplication*)application {

? ? // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

? ? [self.unityVC applicationDidBecomeActive:application];

}

- (void)applicationWillTerminate:(UIApplication*)application {

? ? // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

? ? // Saves changes in the application's managed object context before the application terminates.

? ? [self saveContext];

? ? [self.unityVC applicationWillTerminate:application];

}

#pragma mark - Core Data stack

@synthesizepersistentContainer =_persistentContainer;

- (NSPersistentContainer*)persistentContainer {

? ? // The persistent container for the application. This implementation creates and returns a container, having loaded the store for the application to it.

? ? @synchronized (self) {

? ? ? ? if (_persistentContainer == nil) {

? ? ? ? ? ? _persistentContainer = [[NSPersistentContainer alloc] initWithName:@"xcode10_3orignal"];

? ? ? ? ? ? [_persistentContainer loadPersistentStoresWithCompletionHandler:^(NSPersistentStoreDescription *storeDescription, NSError *error) {

? ? ? ? ? ? ? ? if(error !=nil) {

? ? ? ? ? ? ? ? ? ? // Replace this implementation with code to handle the error appropriately.

? ? ? ? ? ? ? ? ? ? // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.


? ? ? ? ? ? ? ? ? ? /*

?? ? ? ? ? ? ? ? ? ? Typical reasons for an error here include:

?? ? ? ? ? ? ? ? ? ? * The parent directory does not exist, cannot be created, or disallows writing.

?? ? ? ? ? ? ? ? ? ? * The persistent store is not accessible, due to permissions or data protection when the device is locked.

?? ? ? ? ? ? ? ? ? ? * The device is out of space.

?? ? ? ? ? ? ? ? ? ? * The store could not be migrated to the current model version.

?? ? ? ? ? ? ? ? ? ? Check the error message to determine what the actual problem was.

? ? ? ? ? ? ? ? ? ? */

? ? ? ? ? ? ? ? ? ? NSLog(@"Unresolved error %@, %@", error, error.userInfo);

? ? ? ? ? ? ? ? ? ? abort();

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }];

? ? ? ? }

? ? }


? ? return _persistentContainer;

}

#pragma mark - Core Data Saving support

- (void)saveContext {

? ? NSManagedObjectContext *context = self.persistentContainer.viewContext;

? ? NSError*error =nil;

? ? if([contexthasChanges] && ![contextsave:&error]) {

? ? ? ? // Replace this implementation with code to handle the error appropriately.

? ? ? ? // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.

? ? ? ? NSLog(@"Unresolved error %@, %@", error, error.userInfo);

? ? ? ? abort();

? ? }

}

@end

頭文件

@class UnityAppController;

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@property (nonatomic , strong)UIWindow *unityWindow;

@property (nonatomic , strong)UnityAppController *unityVC;

@property(readonly,strong)NSPersistentContainer*persistentContainer;

- (void)saveContext;

- (void)showUnityWindow;

- (void)hideUnityWindow;

步驟九

真機(jī)編譯成功,但是crash,屏蔽InitCrashHandling(); ok了

步驟十

xcode10.1中同樣步驟集成進(jìn)來,連接真機(jī)報(bào)錯(cuò)如下:

修改方式為在endif下面return一個(gè)設(shè)備就可以了,比如return device.iPhonex

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容