/// <summary> /// Registers device to receive remote notifications from GCM. /// </summary> public void Register() { GCM.SetRegisteredCallback(OnDeviceRegistered); GCM.SetMessageCallback(OnReceivedMessage); GCM.Register(new string[] { "1064222689329" }); }
private void Awake() { GCM.Initialize(); //create GCMReceiver // Set callbacks GCM.SetErrorCallback(errorId => Debug.Log("Parse notification error: " + errorId)); GCM.SetUnregisteredCallback(registrationId => Debug.Log("Parse notification Unregistered: " + registrationId)); GCM.SetDeleteMessagesCallback(total => Debug.Log("Parse notification DeleteMessages " + total)); GCM.SetMessageCallback(HandleMessage); }
// Use this for initialization void Start() { // Create receiver game object GCM.Initialize(); // Set callbacks GCM.SetErrorCallback((string errorId) => { Debug.Log("Error!!! " + errorId); GCM.ShowToast("Error!!!"); _text = "Error: " + errorId; }); GCM.SetMessageCallback((Dictionary <string, object> table) => { Debug.Log("Message!!!"); GCM.ShowToast("Message!!!"); _text = "Message: " + System.Environment.NewLine; foreach (var key in table.Keys) { _text += key + "=" + table[key] + System.Environment.NewLine; } }); GCM.SetRegisteredCallback((string registrationId) => { Debug.Log("Registered!!! " + registrationId); GCM.ShowToast("Registered!!!"); _text = "Register: " + registrationId; }); GCM.SetUnregisteredCallback((string registrationId) => { Debug.Log("Unregistered!!! " + registrationId); GCM.ShowToast("Unregistered!!!"); _text = "Unregister: " + registrationId; }); GCM.SetDeleteMessagesCallback((int total) => { Debug.Log("DeleteMessages!!! " + total); GCM.ShowToast("DeleteMessaged!!!"); _text = "DeleteMessages: " + total; }); }
void SetCallbacks() { Application.RegisterLogCallbackThreaded(HandleLog); /*GSApi.GSMessageReceived += (GS, args)=> * { * if(args.Message["@class"] as string == ".ChallengeAcceptedMessage"){ #if UNITY_ANDROID && !UNITY_EDITOR * GCM.ShowToast("Challenge Accepted"); #else * if (Debug.isDebugBuild) Debug.Log("Challenge Accepted"); #endif * } * else if(args.Message["@class"] as string == ".ChallengeDeclinedMessage"){ #if UNITY_ANDROID && !UNITY_EDITOR * GCM.ShowToast("Challenge Declined"); #else * if (Debug.isDebugBuild) Debug.Log("Challenge Accepted"); #endif * } * else if(args.Message["@class"] as string == ".ChallengeChatMessage"){ #if UNITY_ANDROID && !UNITY_EDITOR * GCM.ShowToast("Challenge Chat Recieved"); #else * if (Debug.isDebugBuild) Debug.Log("Challenge Chat Recieved"); * GameGlobals.messageCount++; #endif * } * * };*/ #if UNITY_ANDROID && !UNITY_EDITOR FacebookManager.sessionOpenedEvent += delegate() { if (Debug.isDebugBuild) { Debug.Log("facebook callback worked"); } //we assume that this can will only be called if session is invalid or we are on a new device. Hashtable response = GSApi.facebookConnect(FacebookAccess.getAccessToken()); if ((string)response["@class"] == ".AuthenticationResponse" && (string)response["authToken"] != null) { GameGlobals.online = true; Hashtable details = GSApi.accountDetails(); if (details["userId"] != null) { GameGlobals.userID = (string)details["userId"]; } if (!GCM.IsRegistered()) { GCM.Register(); } GSApi.registerForPush(GCM.GetRegistrationId()); } else { GameGlobals.online = false; } }; #endif #if UNITY_ANDROID && !UNITY_EDITOR GCM.SetErrorCallback((string errorId) => { if (Debug.isDebugBuild) { Debug.Log("Error!!! " + errorId); } GCM.ShowToast("Error!!!"); _text = "Error: " + errorId; }); GCM.SetMessageCallback((Dictionary <string, object> table) => { if (Debug.isDebugBuild) { Debug.Log("Message!!!"); } GCM.ShowToast("Message!!!"); _text = "Message: " + System.Environment.NewLine; foreach (var key in table.Keys) { _text += key + "=" + table[key] + System.Environment.NewLine; } }); GCM.SetRegisteredCallback((string registrationId) => { //if(FacebookAccess.isSessionValid() && }); #endif }