Integrating Unity in Swift project - ios

Well, I have seen and tried most of tutorials referenced from similar questions "How to integrate Unity iOS code into Swift project". But all my attempts were failed with linker error "No such symbol for architecture arm_64" or "No such symbol for architecture x86_64". I have tried different build options in Unity side, no success.
Common minus of all of that tutorials / articles is: all of them outdated, latest version of Unity I have found article is 2018.2.2f1, my version of Unity is 2018.2.20f1.
So, anyone have idea how integrate Unity 2018.2.20+ iOS builded code into Swift 4.2 (XCode 10) project?
Any help will be great appreciated.

Here is how I have integrated unity in my swift project.
Create new Xcode project (using swift)
(create bridging header step) Create new class File -> New -> Cocoa touch class and select language Objective C it will ask for create bridging header choose create
Goto https://github.com/jiulongw/swift-unity and download zip file
Open downloaded file and unzip it. Go to Xcode folder -> DemoApp-> You will find Unity Folder copy paste to your project (if you drag and drop it make sure you check the check box for copy at destination)
open your new Xcode project and auto generated unity project side by side so you can copy paste it easily
copy Classes Folder from unity Xcode project to your Xcode project to the unity Folder of step 4
copy Library Folder from unity Xcode project to your Xcode project to the unity Folder of step 4
copy Data Folder from unity Xcode project to your Xcode project to the unity Folder of step 4
Important Goto Xcode project tap on name of project on left side there will be two options Project and target. Select project on centre main window you can see Configuration Expand it and against the name of your project choose Unity from drop drown
Goto Classes Folder that you have copied in step
And either delete main.mm file or comment everything
goto folder you have downloaded in step3 Copy all code of AppDelegate.swift to your AppDelegate.swift file
In your Xcode project search for YourProjectFileName-Bridging-Header and copy paste
#ifndef BRIDGING_HEADER
#define BRIDGING_HEADER
#import <UIKit/UIKit.h>
#import "UnityUtils.h"
#import "UnityAppController.h"
#import "UnityInterface.h"
#endif /* BRIDGING_HEADER */
Copy paste LaunchScreen-iPad.xib and LaunchScreen-iPhone.xib to your project and delete LaunchScreen.storyboard
Compile it :] it should compile successfully (not in my case I got error that DeviceSettings.mm there is return statement missing so I just added return deviceUnknown; before the })
You can see step3 downloaded view controller.swift file for see how to show unity view in your screen
Notes: After integrate unity you are not able to run in simulator so you have to run in real device.
it is better to have unity and xcode in same machine. sometime all the framework only get ref of folder so in different machine you may face the issue
at last your project should look like

Related

MyClass is unavailable: cannot find Swift declaration for this class

I am building a custom framework in swift.I have builded the framework for all the architecture. I am using Debug-Universal build in my sample app. Now when I run the app, It works fine in the simulator but while running on the device, I am getting the error Breeze is unavailable: cannot find Swift declaration for this class
When I am using Release-Universal it is giving No such Module BreezeSDK
Follow these steps after creating the universal binaries:
Before lipo, you are building .framework packages for the individual architectures.
For each package:
Traverse to abc.framework/Modules/abc
Copy files .swiftdoc
Go into universal abc
Traverse to abc.framework/Modules/abc
Paste the files you copied in step 2
Repeat these steps for all architectures.
Finally your universal framework package path abc.framework/Modules/abc.swiftmodule/ should contain
those files:
arm.swiftdoc
arm.swiftmodule
arm64.swiftdoc
arm64.swiftmodule
i386.swiftdoc
i386.swiftmodule
x86_64.swiftdoc
x86_64.swiftmodule
The Swift compiler needs swiftmodule map files for each architecture.
Follow these steps
Download Bareeze SDK.
Drag and add Breeze.xcodeproj to your project.
Next, select your application project in the Project Navigator (blue project icon) to navigate to the target configuration window and select the application target under the "Targets" heading in the sidebar.
In the tab bar at the top of that window, open the "General" panel.
Click on the + button under the "Embedded Binaries" section.
Select the top Breeze.framework
Hope this might solve the issue.

swift: add Haneke.framework to xcode 7.0.1 not work

I'm beginner in xcode and swift, So I'm try to add Haneke framework to my project. I do these steps:
Drag Haneke.xcodeproj to your project in the Project Navigator.
Select your project and then your app target. Open the Build Phases panel.
Expand the Target Dependencies group, and add Haneke.framework.
Click on the + button at the top left of the panel and select New Copy Files Phase. Set Destination to Frameworks, and add Haneke.framework.
import Haneke whenever you want to use Haneke.
But I get this error in improt Haneke:
No such module 'Haneke'
Also I'm tried to Clean and Build again but not work for me!
Is there a mistake from me?
Edit:
More Info
I used swift 2.0 and xcode 7.0.1 and development target is 8.0
Also I added some screenshots
Finally I found another solution, At first I opened Haneke project in xcode and create a build then Drag & Drop new compiled file (Haneke.framework) from build folder to my own project and it's working now for me.

Xcode 6: No Frameworks Folder in Project Navigator

I am using Xcode 6 and following an Xcode version 4 tutorial so things are different here and there.
There doesn't seem to be a Frameworks folder in my project navigator and so when I downloaded some .framework files and added them manually in the build phase of my project editor, I had no Frameworks folder to save them in and just let them fall into the top of my project navigator. So they are there, just not in a special folder, and it doesn't look good.
So should Xcode 6 have a frameworks folder automatically, or do I need to create one myself? And if so, how can I do that? (I've only added new files so far).
In Xcode 6, the Frameworks folder is not added by default. You can drag and drop your .framework files into the project navigator (tick 'Copy items if needed'), then select them all > right click > "New Group from Selection" and name the folder 'Frameworks'.
Also, make sure the frameworks are added into the Project > Build Phases > Link Binary With Libraries. If not, drag them there from your newly created 'Frameworks' folder.
In short, no, you shouldn't need to create a Frameworks group yourself as Xcode is doing stuff automatically for you...
Apple are slowly, gently pushing developers in the direction of newer Clang features with the goal of making native iOS development more approachable for newbies who don't have previous experience of compiling and linking with C-based languages.
You'll find that Objective-C projects created with Xcode 6 have new build settings enabled by default including Link Frameworks Automatically (CLANG_MODULES_AUTOLINK) and Enable Modules (C and Objective-C) (CLANG_ENABLE_MODULES).
Suggested reading:
Modules (Clang documentation)
#import vs #import - iOS 7 (excellent Stack Overflow answer)
I found the other answers too confusing (where am I supposed to get .framework files?)
It's way simpler in Xcode 6. Just go to Capabilities and turn Maps on. That's it... really.
I would recommend using drag and drop feature to move files into Xcode. Xcode show you the Choose options for adding these files window [Copy items if needed] [Added folders]
For example Xcode can automatically add relative path ($(PROJECT_DIR)/) to:
Build Settings -> Library Search Paths if you drag and drop a library
Build Settings -> Framework Search Paths if you drag and drop a framework

How can I modify the xCode project automatic which generate by Unity?

I create a Unity project and generate an xCode project . Aways I should and some frameworks or static libs to the xCode project to make it run . So I want make this progress automatic.
I found some tools to modify the xCode project . such as "Mod PBXProj":
https://bitbucket.org/darktable/mod-pbxproj/src
My question is that how can I call the tools(such as "Mod PBXProj") to modify the xCode project after the Unity project generate the xCode project . Or are there any other method to modify the project?
If you will open unity application as a folder, there will be a folder of xCode project, wich unity just copies while build. you can add there any files you whant (or replace), and on every new build, unity you use modified files.

Framework import issue in xcode

Here the problem: For a project at work we need to include an extern API: mobileAppTrackeriOS from HasOffers.
It gives us a framework to include in our projet and instruction to enter in our code.
So I copy the framework in the project directory and drag it into xcode to include it.
But when i want to use it with:
#import <framework/mainheader.h>
The build give me an error :
Lexical or Processor issue 'MobileAppTrackeriOS_arc/MobileAppTracker.h' file not found
I check the framework search path in my target build setting, my main directory where is the framework is here.
I test with "" instead of <> same issue...
i cleaned and rebuilt, try to include directly the header... many ridiculous things... no changes.
So what I forget?
I'm on Xcode 4.5 and develop for iOS 6.0.
A question, can you see if the framework is in Build Phases -> Link binary with Libraries?
If answer is not, you must add in this section.

Resources