Prérequis
Doit avoir un compte développeur iOS
Pour configurer brainCloud afin d'envoyer des notifications à votre application iOS, vous devez fournir un fichier de certificat p12. Suivez ces étapes pour créer un fichier p12 pour votre application.
Configuration du portail brainCloud
Connectez-vous au portail brainCloud
Accédez à Notifications | Paramètres dans l’onglet de conception de votre application
Cliquez sur le bouton Modifier pour les paramètres de notification Apple
Téléchargez votre fichier p12 et entrez le mot de passe utilisé pour créer le fichier p12 dans la boîte de dialogue
Notez qu'une fois que vous avez fait cela, le type de certificat s'affiche (production/sandbox) ainsi que la date d'expiration
Exemple de code Unity
using UnityEngine;
using UnityEngine.iOS;
public class App : MonoBehaviour
{
private BrainCloudWrapper _bc;
private string _wrapperName = "default";
bool tokenSent;
void Start()
{
// Unity
GameObject go = new GameObject();
_bc = go.AddComponent<BrainCloudWrapper>();
_bc.WrapperName = _wrapperName; // définir éventuellement un nom de wrapper
_bc.Init(); // des données supplémentaires, telles que : _appId, _secret et _appVersion, sont extraites du plug-in brainCloud Unity.
DontDestroyOnLoad(go); // conserver l'objet de jeu brainCloud lors des changements de scène
// Authentifiez votre utilisateur avec brainCloud
_bc.AuthenticateAnonymous((response, cbObject) =>
{
Debug.Log(string.Format("[Auth Success] {0}", response));
},
(status, code, error, cbObject) =>
{
Debug.Log(string.Format("[Auth Failed] {0} {1} {2}", status, code, error));
});
tokenSent = false;
UnityEngine.iOS.NotificationServices.RegisterForNotifications(
NotificationType.Alert |
NotificationType.Badge |
NotificationType.Sound);
}
void Update()
{
if (!tokenSent)
{
byte[] token = UnityEngine.iOS.NotificationServices.deviceToken;
// Lorsque le jeton existe et que brainCloud est authentifié
if (token != null && _bc.Client.Authenticated)
{
// Envoyer le jeton à brainCloud
_bc.PushNotificationService.RegisterPushNotificationDeviceToken(
token,
(response, cbObject) =>
{
Debug.Log(string.Format("[Register Success] {0}", response));
}, ((status, code, error, cbObject) =>
{
Debug.Log(string.Format("[Register Failed] {0} {1} {2}", status, code, error));
}));
tokenSent = true;
}
}
}
}