Unity IOS integration - ios

For a project I need to integrate Unity3d in an existing app I know Unity acts as a UIApplicationDelegate. I found an interesting article about this topic but it is not really clear to me how I can resolve my problems this way. Is it possible restart the delegation process from a ViewController? So when I switch to a viewController from my delegate and I want to navigate back then initialize the UIApplicationDelegate again?
Article I found:
http://alexanderwong.me/post/29949258838/building-a-ios-unity-uiview-uiviewcontroller
Thanks in advance

Have you tried using Unity to build a "standard" Unity iOS application, then integrating your existing code into that?
When you build for iOS from Unity, Unity will automatically stick a hook in your Application Delegate, in the following method:
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
You can do other stuff in there, but down the bottom you should see the important line:
[self startUnity:application];
So what you can do is just take that line out of the didFinishLaunching method and put it ... wherever you want. You'll also want to keep a reference to the UIWindow* Unity draws to in your application delegate, so you can switch in and out of it as you please.
So, I'm not completely clear about exactly the things you want to do, but I definitely recommend as a first step you start with an integrated Unity build and work from there, or at least use it as a map if you want to roll your own implementation.

Its been a while, but better late then never ;)
You can not "restart" the delegation stuff. The UnityAppController is an AppDelegate, not a ViewController.
But you can decide when unity is started the first time. After that, unity is running and you have to either use the applicationDidEnterBackground call in the UnityAppController (for pre Unity 5) or just call setPause:true (using Unity 5) which stops the unity render loop. Just dont forget to reactivate it once you navigate back to the UnityViewController.
For the "how to start unity when u want to": Either subclass UnityAppController and override startUnity:(UIApplication*) application with an empty implementation. Then you call [super startUnity..] once you want to activate it.
The other way is not to subclass but create your own UnityAppController object and call all the methods (applicationDidFinsishLaunching etc.). Then you just wait with the initialization till you need unity for the first time. But i would recommend the first option.
You can also look here for a more detailed Description how i did it: http://www.markuszancolo.at/2014/05/integrating-unity-into-a-native-ios-app

Related

Why doesn't my Swift app have AppDelegate or SceneDelegate?

So I'm new to Swift. I see it's a fast-moving language.
But so many tutorials I see have AppDelegate and SceneDelegate as standard init files, why don't I have any? Why can't I seem to find an option for them?
The tutorials include one from July 2020 so I'm guessing this is some sort of recent update. How should I approach the two types of apps with different file types? As a "Veteran" programmer, which is more advantageous?
Thanks everyone. Happy Coding.
When creating a new iOS app, if you select SwiftUI App for the life cycle, this replaces the use of AppDelegate and SceneDelegate.
If you want a classic lifecycle delegate, you can select UIKit App Delegate instead.
The only way I know to get the result you did is to choose "SwiftUI" for Interface and "SwiftUI App" for Life Cycle in the New Project dialog. If you choose "Storyboard" for Interface, or "UIKit App Delegate" for Life Cycle, you will get the files you expected.

How to wrap existing iOS code in a new Appcelerator module?

This seems like a basic request, but I can't find the answer to it anywhere. I want to wrap some existing iOS code that I wrote, in a Appcelerator module. That's it. Important points:
I am NOT wrapping a pre-existing 3rd party iOS SDK.
I wrote the iOS code being wrapped.
Code is verified as working within xcode.
There are no .a files. There are 2x .h files and 2x .m files though.
There are no UI elements in the iOS code as it is only designed to connect the native bluetooth hardware to the app.
I have created a generic appcelerator iOS module project, built it, and successfully called the generic ID function within my app.
I cannot figure out how to successfully edit the generic module so that it utilizes my code. Every attempt results in it refusing to compile, and it's maddening.
I do not have access to Hyperloop.
Once I can successfully build the wrapped module, I would call an initialization function which triggers a native bluetooth hardware search. Once connected, there are functions within the module to send commands to the hardware and receive data back. This is the official documentation I've followed so far:
http://docs.appcelerator.com/platform/latest/#!/guide/iOS_Module_Quick_Start
That helped me build the blank module, include it in the app, and ensure that it worked by calling the built in test property. From there it stops short of actually telling me what I need to know. These are the closest things I've found so far, while still not being what I need:
http://docs.appcelerator.com/platform/latest/#!/guide/iOS_Module_Project-section-43288810_iOSModuleProject-AddaThird-PartyFramework
appcelerator module for existing ios project sdk
Heck, I still don't even know if I can do this within studio or if I have to edit the generic module in Xcode. Help! :) Many thanks in advance.
so first of all, this is not best practice and will cause possible problems in the future when the SDK changes and your module still relies on outdated core API's.
Regarding your question, you could either create a new component that subclasses the existing class, e.g.
class TiMyModuleListViewProxy : TiUiListViewProxy {
}
and call it with
var myList = MyModule.createListView();
or you write a category to extend the existing API with your own logic, e.g.
#interface TiUIListViewProxy (MyListView)
- (void)setSomethingElse:(id)value;
#end
#implementation TiUIListViewProxy (MyListView)
- (void)setSomethingElse:(id)value
{
// Set the value of "somethingElse" now
}
#end
I would prefer the second option since it matches a better Objective-C code-style, but please still be aware of the possible core-changes that might effect your implementation in the feature. Thanks!

Accessing UIApplication.sharedApplication() from a framework

I use a framework to share common code between my main application and a Today Extension. I frequently run into scenarios where I am attempting to access UIApplication.sharedApplication() (the main application singleton) that is running from my framework, to show alerts, open URLs, show image pickers, show spin selectors, etc.
As a temporary solution I have a global variable in the framework that I set to the UIApplication when the application starts, then the framework relies on that variable. This method feels wrong to me and I would love to know of a better solution.
What is the best practice for accessing the UIApplication singleton from my framework?
Most likely you are missing the following import statement:
#import <UIKit/UIKit.h>
If you can build your framework, when it uses UIApplication.sharedApplication(), it is good solution as far as I can see than saving UIApplication.sharedApplication() in some variable.

Creating an iOS library or framework using libgdx (roboVM)

Is it possible to create an iOS library or framework using libgdx (RoboVM) that can be imported into Xcode?
Background:
One of my colleagues has created a 3D visualisation app as a libgdx project for android and windows desktop. It can be compiled to run on iOS using RoboVM. However, I would like to wrap extra native user interface elements around it using Xcode. I know its possible to build the user interface programmatically via RoboVM but I would be keen to investigate if its possible to bring the existing work into Xcode. I don't need to edit the 3D visualisation component but add extra GUI elements around the 3D Vis window. I thought compiling the libgdx (RoboVM) code to a framework or library might be a solution that could be imported?!
Yes you can do it.
All you need to create a method, say initRoboVM(), This will be called by your code when you want to initialize libgdx. You'll need to pass the app path in, which you can hardcode when you're testing.
initRoboVM() will need some modifications, namely it should not call your Java app's main method, well, at least, that's what well behaving libraries should not do IMO. It should also not call rvmShutdown.
You can get further information from here
Thanks :)
I asked the RoboVM team directly. Their answer: It's not a native function, but it certainly can be done.
The complete message...
Hi,
Sorry for the late reply. This use case is not something we're going
to do now. It is possible though if you're prepared to do some
patching of RoboVM. Search the RoboVM Google Group and you should find
others who have managed to get this working.
We get this request every know and then so we will add support for
this eventually.
Regards, Niklas

How to turn a project with xib into a pure code one?

I tried to turn a xib project which is downloaded from iOS Developer Library of Apple, into a pure code one for further use, but it didn't work.
I wonder what should I pay attention to when I do this kind of conversion, and I wonder it will help me improve my skill of iOS developing.
Converting the Xib file into pure code part is not a very big task, you just need to be carefully replace the items created via Interface builder by your code part. You can follow this sequence while converting such projects :-
1) Display the elements made via IB with your code.
2) Make sure the delegates and datasources to be connected via code if they were connected via IB.
3) Check for the IBActions, if any to be replaced.
4) Lastly, if you are not using ARC or the Project that is being converted not using ARC then the dealloc part or viewDidUnload method, where we generally make the objects nil and release.
Hope it helps you :)
There are some tool available. For example, http://kosmaczewski.net/projects/nib2objc/

Resources