Description#
This section describes usage patterns and guidelines for common integration scenarios enabled using RaveSocial APIs that venture beyond the drop-in experience found in the included scene pack.
The scene pack provides a built in user profile experience, for example, but you may create an app-specific profile experience and this guide explains some common scenarios you may encounter.
Using App Data Keys for Save Game or Cloud Storage ID#
To get a stable index for data lookup, especially if Rave ID was used in the past, then RaveAppDataKeys is the recommended API to use. Simply implement the protocol RaveAppDataKeysStateObserver.
- (void)appDataKeyStateChanged:(NSString *)selectedKey unresolvedKeys:(NSArray *)unresolvedKeys
By default the selected key returned by this interface will be the current key for the current user. In a typical case, it will be a randomly generated key in a 32 character hex format. If no key had been previously selected for the current application this random key will be the default. The selected key will be non-nil provided that unresolvedKeys is empty, which will usually be the case. When there are unresolved keys, and you are online, then your integration will need to choose between the unresolved keys. Rave will never make a choice between unresolved keys, this is strictly up to the developers discretion.
The integration will choose between unresolved keys when a merge takes place between two users that have already used the current application. At this point either present the user with a choice between the unresolved keys or choose one automatically. With both keys the application can look up information about the two indexes to choose from or present the information to the user. Once a key has been chosen call +[RaveAppDataKeys selectKey:callback:]
(see selectKey for more information).
User Profile Scenarios#
Code samples for custom user profile scenarios are provided in SampleRaveProfileScene.m included in your distribution package.
Accessing the current user#
RaveSocial.currentUser
is a shortcut method for accessing the current user.
Provided RaveSettings.General.AutoGuestLogin
is enabled this value should never be nil, even after a log out operation. You can access a variety of fields to populate user’s profile screen including display name, email, and profile picture URL.
Observing the current user#
New in Rave 3.0.2 is an API to register observers for changes to the current user: -[RaveUsersManager addCurrentUserObserver:]. When a change occurs, usually as the result of an asynchronous operation, all registered observers will be notified with an array of the changed properties of the current user.
It is recommended that you leverage this feature in your custom user profile screen for displayName and pictureURL (or pictureImage), since those values may change as a result of an asynchronous operation that you’ve triggered that didn’t explicitly change those user fields.
Observers should implement the RaveCurrentUserObserver protocol, which consists of one method: -[RaveCurrentUserObserver userChanged:].
- (void)userChanged:(NSArray *)changedKeys {
if ([changedKeys containsObject:@"displayName"]) {
// Update UI with new display name
} else if ([changedKeys containsObject:@"pictureImage"]) {
// Update UI with new profile picture
} else if ([changedKeys containsObject:@"pictureURL"]) {
// Update picture image
}
}
Displaying the profile picture#
The current user has a reference to the pictureURL, it is always a remotely stored image. It will either be stored on Rave’s servers or on a third party’s server, depending on the source of the image.
On iOS you have the option of fetching the image from URL yourself using RaveSocial.currentUser.pictureURL
, or there is a convenience method to do it for you:
id<RaveUser> current = RaveSocial.currentUser;
[current updatePictureImage:^(NSError * error) {
if (error) {
[RaveSocial.errorDelegate showError:error];
} else {
// perform some other action with the image
// e.g. current.pictureImage
}
}];
Changing Profile Picture#
There is a common method on all platforms that takes a local file url and pushes the binary data for the image to the Rave backend so that the profile picture is available on any device.
NSString * imageURL = someLocalImageURL;
[RaveSocial.usersManager pushProfilePicture:imageURL withCallback:^(NSError *error) {
if (error){
// do something in the error case
[RaveSocial.errorDelegate showError:error];
}
}];
Changing the display name#
New in Rave 3.0.2 is an API to modify the current user without staging the changes in the model. -[RaveUsersManager pushUserChanges:callback:].
RaveUserChanges * changes = [RaveUserChanges userChanges];
changes.displayName = someOtherName;
[RaveSocial.usersManager pushUserChanges:changes callback:^(NSError * error) {
if (error) {
// Do something with the error
}
}];
Use this new method rather than the legacy method -[RaveUsersManager pushCurrent:].
Logging out#
If RaveSettings.General.AutoGuestLogin
is enabled a new anonymous user will automatically be created when user logs out. Prior to the logOut completion callback firing it is suggested that you prevent the user from interacting with Rave similar to what is shown in the snippet below.
[RaveSocial.progressDelegate showWithMessage:"Signing out..." andCancelCallback:nil];
[RaveSocial logOut:^(NSError * error) {
[RaveSocial.progressDelegate dismiss];
if (error) {
// handle error logging out
}
}];
Opening common scenes#
Opening the Login Scene#
Opening the login scene allows the user to sign in using their BigFish account by default. It also provides the user with a convenient shortcut to the create account scene through a button.
The following sample code shows an example of showing the scene and also capturing the result of any login or account creation that occurs. In the case that a new account is created the result will be successful and the signup data will be valid. For details of the signup data see the appropriate documentation in the BigFishScenePack.
RaveLoginScene * loginScene = [RaveLoginScene scene]; loginScene.signUpDataCallback = ^(RaveCallbackResult result, BigFishSignUpData * signUpData, NSError * error) { if (result == RaveResultSuccessful) { if (signUpData != nil) { } } else if (result == RaveResultCanceled) { } else { [RaveSocial.errorDelegate showError:error]; } }]; [loginScene show];
The Create Account scene allows the user to create a BigFish account. It also provides the user with a convenient shortcut to the login scene through a button.
The following example code shows an example of showing the scene and also capturing the result of any login or account creation that occurs. In the case that an account is created the result will be successful and the signup data will be valid. For details of the signup data see the appropriate documentation in the BigFishScenePack.
RaveSignUpEmailScene * signUpScene = [RaveSignUpEmail scene]; signUpScene.signUpDataCallback = ^(RaveCallbackResult result, BigFishSignUpData * signUpData, NSError * error) { if (result == RaveResultSuccessful) { if (signUpData != nil) { } } else if (result == RaveResultCanceled) { } else { [RaveSocial.errorDelegate showError:error]; } }]; [signUpScene show];You’ll want to show the Find Friends scene if you want an easy way to attract users to attaching Facebook, Google, Phonebook contacts, etc. to their Rave account.
RaveFindFriendsScene * findFriendsScene = [RaveFindFriendsScene scene]; findFriends.sceneCompleteCallback = ^{ // capture when this scene is closed }; [findFriendsScene show];