SHARE
TWEET

Untitled

a guest Feb 9th, 2018 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.IO;
  4.  
  5. using System;
  6. using System.Net;
  7. using AssemblyCSharpfirstpass;
  8. using com.shephertz.app42.paas.sdk.csharp;
  9. using com.shephertz.app42.paas.sdk.csharp.pushNotification;
  10.  
  11. public class PushSample: MonoBehaviour, App42NativePushListener
  12. {
  13.     private string message="App42 Push Message";
  14.    
  15.     private int viewHeight = Screen.height / 10;//48
  16.     private int viewWidth = (Screen.width *3)/4 ;
  17.     private int leftGap = Screen.width / 10;
  18.     private int fontSize=Screen.width / 20;
  19.     private string userName = "";
  20.     private string myMsg = "Hi I am using Push App42";
  21.     public string app42Response="";
  22.     public const string ApiKey ="my key";
  23.     public const string SecretKey="my secret key";
  24.     public const string GoogleProjectNo="my 12 digits number";
  25.     public const string UserId="654321";
  26.    
  27.     void OnGUI()
  28.     {
  29.         GUIStyle style=new GUIStyle();
  30.         style.fontSize = fontSize;
  31.        
  32.         GUI.Label(new Rect (leftGap, viewHeight, viewWidth, viewHeight*2), message,style);
  33.  
  34.         app42Response=Callback.response;
  35.         app42Response = GUI.TextField (new Rect (leftGap, viewHeight*3, viewWidth, viewHeight*2),app42Response);
  36.         userName = GUI.TextField (new Rect (leftGap, viewHeight*5, viewWidth, viewHeight),userName);
  37.         myMsg = GUI.TextField (new Rect (leftGap, viewHeight*6, viewWidth, viewHeight),myMsg);
  38.         //userName = GUI.TextField (new Rect (5, 150, 300, 30),userName);
  39.         //myMsg = GUI.TextField (new Rect (5, 190, 300, 40),myMsg);
  40.        
  41.         if (GUI.Button(new Rect (leftGap, viewHeight*7, viewWidth, viewHeight), "Send Push To User"))
  42.         {
  43.             sendPushToUser(userName,myMsg);
  44.         }
  45.         if (GUI.Button(new Rect (leftGap, viewHeight*8, viewWidth, viewHeight), "Send Push To All"))
  46.         {
  47.             sendPushToAll(myMsg);
  48.         }
  49.  
  50.     }
  51.  
  52.     public void Start (){
  53.         DontDestroyOnLoad (transform.gameObject);
  54.         App42API.Initialize(ApiKey,SecretKey);
  55.         App42API.SetLoggedInUser(UserId);
  56.         //Put Your Game Object Here
  57.         App42Push.setApp42PushListener (this);
  58.         #if UNITY_ANDROID
  59.         App42Push.registerForPush (GoogleProjectNo);
  60.         message=App42Push.getLastPushMessage();
  61.         #endif
  62.     }
  63.  
  64.     public void onDeviceToken(String deviceToken){
  65.         message="Device token from native: "+deviceToken;
  66.         String deviceType = App42Push.getDeviceType ();
  67.         if(deviceType!=null&&deviceToken!=null&& deviceToken.Length!=0)
  68.             App42API.BuildPushNotificationService().StoreDeviceToken(App42API.GetLoggedInUser(),deviceToken,
  69.                                                     deviceType,new Callback());
  70.    }
  71.     public void onMessage(String msg){
  72.         message="Message From native: "+msg;
  73.        
  74.     }
  75.         public void onError(String error){
  76.         message="Error From native: "+error;
  77.        
  78.     }
  79.     public void sendPushToUser(string userName,string msg){
  80.        
  81.         App42API.BuildPushNotificationService().SendPushMessageToUser(userName,msg,new Callback());
  82.        
  83.     }
  84.     public void sendPushToAll(string msg){
  85.        
  86.         App42API.BuildPushNotificationService().SendPushMessageToAll(msg,new Callback());
  87.        
  88.     }
  89. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top