Of course, a quick introduction would help, to get you started — right?
Especially since we don't have any Obj-C documentation on the website yet. This is still a work in progress, after all. 😉
After linking Flox to your game, you have to
#import "Flox.h"
Then just start up Flox like this. This will already collect a lot of information about your players, e.g. country, device type, etc.
[Flox startWithGameID:@"gameID" key:@"gameKey" version:@"1.0"];
With Events, you can collect more finegrained data about how players are using your game. Pass custom properties to get a nice visualization of the details.
[Flox logEvent:@"GameStarted"];
[Flox logEvent:@"MenuNavigation"
properties:@{ @"from": @"MainMenu", @"to": @"SettingsMenu" }];
To send and retrieve scores, first set up a leaderboard in the web interface. Using its ID as an identifier, you are good to go.
[Flox postScore:999 ofPlayer:@"Mike" toLeaderboard:@"default"];
[Flox loadScoresFromLeaderboard:@"default" timeScope:FXTimeScopeAllTime
onComplete:^(NSArray *scores, NSError *error)
{
// scores will be of type "FXScore".
NSLog(@"received %d scores", (int)scores.count);
}];
Now a feature I especially love: Entities. They allow you to store arbitrary data on the Flox servers.
Just create a subclass of "FXEntity" like this:
@interface CustomEntity : FXEntity
@property (nonatomic, copy) NSString *name;
@property (nonatomic, assign) NSInteger age;
@end
(The .m-file does not need any content.)
Now create an instance of this class and save it to the server.
CustomEntity* entity = [CustomEntity entity];
entity.name = @"shilo";
entity.age = 24;
[entity saveQueued]; // save next time you're online
If you're online, it will be stored right away; otherwise, the next time you connect to the net (even if that only happens in the next game session).
If you need more control, you can do it like this:
[entity save:^(id entity, NSInteger httpStatus, NSError *error)
{
if (!error)
[Flox logInfo:@"Successfully saved entity on server."];
}];
To load an entity, you just have to know its "id" -- which is a string property on any entity.
CustomEntity loadByID:@"abc"
onComplete:^(id entity, NSInteger httpStatus, NSError *error)
{
// 'entity' contains the loaded object.
}];
If you don't know the ID, you can even query for the object in SQL-style.
FXQuery *query = [CustomEntity queryWhere:@"name == ?", @"shilo"];
[query find:^(NSArray *entities, NSInteger httpStatus, NSError *error)
{
NSLog(@"Found %d shilos ;-)", entities.length);
}];
Okay, that was a fast-forward introduction to Flox! Details can be found in the API reference.
Have fun! I'd be happy about any feedback!