-
Notifications
You must be signed in to change notification settings - Fork 56
Hello World iOS
Diego Gomez Deck edited this page May 27, 2015
·
6 revisions
- File > New > Project...
- Set these options trough the wizard steps:
- Template: iOS > Application > Single View Application
- Give a name to your application
- Locate the folder to save your project
Once you created your project some configuration is required.
- Set the Deployment Target 6.1 within the General Section of the setting screen.
- Link the g3m framework: scroll down to the Linked Frameworks and Libraries item and click on + button. Click on Add Other... button to locate your local copy of g3m framework. Open it and wait for indexing files.
- Link the g3m static library: once the framework is indexed, click on the same + button again to add the library. The popup window shows you the g3m library now on your Workspace. Select it and click on Add button.
- Link the other required frameworks and libraries the same way you did with g3m library:
- CoreData.framework
- OpenGLES.framework
- QuartzCore.framework
- CFNetwork.framework
- Security.framework
- libsqlite3.dylib
- libicucore.dylib
At the end, your Linked Frameworks and Libraries section will look this:
Go to the Build Settings section and use the searcher to easily find and set the following options:
- C++ Language Dialect: Compiler Default
- C++ Standard Library: Compiler Default
- Preprocessor Macros:
- Debug: C_CODE DEBUG=1
- Release: C_CODE
- Other Linker Flags: -ObjC
- Click on the Main_iPhone.storyboard on the Project Navigator Panel to open it.
- Now click on the view to get it selected and show the Identity inspector (third button on the right panel).
- Set G3MWidget_iOS as the custom class of your view
- Show the Assistant editor (second button on the right toolbar) and you will get a split screen showing the storyboard on the left and the ViewController header file on the right.
- Ctrl + click on the view and drag and drop on the view controller view, after
@interface HWViewController : UIViewController
and before@end
lines to create a reference of your view in your code (IBOutlet). Give a name for the reference on the balloon. Once you click connect you will get this code on your view controller:@property (strong, nonatomic) IBOutlet G3MWidget_iOS *g3mWidget;
Tip: Add a class reference to fix the error. Add@class G3MWidget_iOS;
after#import <UIKit/UIKit.h>
line.
- Repeat the same process for the Main_iPad.storyboard.
- This time when referencing the view, drag and drop over the existing property instead of adding a new one.
You may have a g3m widget on any view you want but for this example we select the main view to get a full screen g3m widget.
- The first step is renaming the view controller. g3m uses C++ code thus your view controller should have .mm extension to get it working. Rename
YourPrefixViewController.m
toYourPrefixViewController.mm
and save. - Go to the
viewDidLoad
method and add this lines after the comment:G3MBuilder_iOS builder([self g3mWidget]); builder.initializeWidget();
- You will have to import some classes:
#import <G3MiOSSDK/G3MWidget_iOS.h>
#import <G3MiOSSDK/G3MBuilder_iOS.hpp>
- Add some new methods to get the widget working:
// Start animation when view has appeared
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
// Start the glob3 render loop
[self.g3mWidget startAnimation];
}
// Stop the animation when view has disappeared
- (void)viewDidDisappear:(BOOL)animated
{
// Stop the glob3 render loop
[self.g3mWidget stopAnimation];
[super viewDidDisappear:animated];
}
// Release property
- (void)viewDidUnload
{
self.g3mWidget = nil;
}
- Save all the files. Clean and build the project.
- Run the app either on your iOS device or the iOS Simulator and say Hello to your g3m world!
You can find the full Hello World project here