public void Test_0009_Install_With_Null_Device() { this.LogIn(); ClearClientRequest(); client.AddResponse(200, null); KiiUser.PushInstallation(true).Install(null, KiiPushInstallation.DeviceType.IOS); }
public void Test_Uninstall_With_Empty_Device() { this.LogIn(); ClearClientRequest(); client.AddResponse(200, null); KiiUser.PushInstallation(true).Uninstall("", KiiPushInstallation.DeviceType.IOS); }
public void Test_0011_Uninstall_Android() { this.LogIn(); ClearClientRequest(); client.AddResponse(200, null); KiiUser.PushInstallation(false).Uninstall("deviceID1", KiiPushInstallation.DeviceType.ANDROID); Assert.AreEqual(KiiHttpMethod.DELETE, client.RequestMethod [0]); Assert.AreEqual("https://api.kii.com/api/apps/appId/installations/ANDROID:deviceID1", client.RequestUrl [0]); }
public void Test_0014_Uninstall_iOS_Development() { this.LogIn(); ClearClientRequest(); client.AddResponse(200, null); KiiUser.PushInstallation(true).Uninstall("deviceID4", KiiPushInstallation.DeviceType.IOS); Assert.AreEqual(KiiHttpMethod.DELETE, client.RequestMethod [0]); Assert.AreEqual("https://api.kii.com/api/apps/appId/installations/IOS:deviceID4", client.RequestUrl [0]); }
public void Test_0004_Install_iOS_Development() { this.LogIn(); ClearClientRequest(); client.AddResponse(200, null); KiiUser.PushInstallation(true).Install("deviceID4", KiiPushInstallation.DeviceType.IOS); Assert.AreEqual(KiiHttpMethod.POST, client.RequestMethod [0]); Assert.AreEqual("https://api.kii.com/api/apps/appId/installations", client.RequestUrl [0]); Assert.AreEqual("{\"installationRegistrationID\":\"deviceID4\",\"deviceType\":\"IOS\",\"development\":true}", client.RequestBody[0]); }
public void Test_Uninstall_With_Empty_Device_Async() { this.LogIn(); ClearClientRequest(); client.AddResponse(200, null); KiiUser.PushInstallation(true).Uninstall("", KiiPushInstallation.DeviceType.IOS, (Exception e) => { Assert.IsNotNull(e); Assert.IsInstanceOfType(typeof(ArgumentException), e); }); }
public void Test_0001_Install_Android() { this.LogIn(); ClearClientRequest(); client.AddResponse(200, null); KiiUser.PushInstallation(false).Install("deviceID1", KiiPushInstallation.DeviceType.ANDROID); Assert.AreEqual(KiiHttpMethod.POST, client.RequestMethod [0]); Assert.AreEqual("https://api.kii.com/api/apps/appId/installations", client.RequestUrl [0]); Assert.AreEqual("{\"installationRegistrationID\":\"deviceID1\",\"deviceType\":\"ANDROID\"}", client.RequestBody[0]); }
public void Test_0017_Uninstall_Async_iOS() { this.LogIn(); ClearClientRequest(); client.AddResponse(200, null); KiiUser.PushInstallation(false).Uninstall("deviceID3", KiiPushInstallation.DeviceType.IOS, (Exception e) => { Assert.AreEqual(KiiHttpMethod.DELETE, client.RequestMethod [0]); Assert.AreEqual("https://api.kii.com/api/apps/appId/installations/IOS:deviceID3", client.RequestUrl [0]); }); }
public void Test_0016_Uninstall_Async_Android_Development() { this.LogIn(); ClearClientRequest(); client.AddResponse(200, null); KiiUser.PushInstallation(true).Uninstall("deviceID2", KiiPushInstallation.DeviceType.ANDROID, (Exception e) => { Assert.AreEqual(KiiHttpMethod.DELETE, client.RequestMethod [0]); Assert.AreEqual("https://api.kii.com/api/apps/appId/installations/ANDROID:deviceID2", client.RequestUrl [0]); }); }
public void Test_0007_Install_Async_iOS() { this.LogIn(); ClearClientRequest(); client.AddResponse(200, null); KiiUser.PushInstallation(false).Install("deviceID3", KiiPushInstallation.DeviceType.IOS, (Exception e) => { Assert.AreEqual(KiiHttpMethod.POST, client.RequestMethod [0]); Assert.AreEqual("https://api.kii.com/api/apps/appId/installations", client.RequestUrl [0]); Assert.AreEqual("{\"installationRegistrationID\":\"deviceID3\",\"deviceType\":\"IOS\"}", client.RequestBody[0]); }); }
public void Test_0006_Install_Async_Android_Development() { this.LogIn(); ClearClientRequest(); client.AddResponse(200, null); KiiUser.PushInstallation(true).Install("deviceID2", KiiPushInstallation.DeviceType.ANDROID, (Exception e) => { Assert.AreEqual(KiiHttpMethod.POST, client.RequestMethod [0]); Assert.AreEqual("https://api.kii.com/api/apps/appId/installations", client.RequestUrl [0]); Assert.AreEqual("{\"installationRegistrationID\":\"deviceID2\",\"deviceType\":\"ANDROID\",\"development\":true}", client.RequestBody[0]); }); }
void RegisterPush() { #if UNITY_IPHONE KiiPushInstallation.DeviceType deviceType = KiiPushInstallation.DeviceType.IOS; #elif UNITY_ANDROID KiiPushInstallation.DeviceType deviceType = KiiPushInstallation.DeviceType.ANDROID; #else KiiPushInstallation.DeviceType deviceType = KiiPushInstallation.DeviceType.ANDROID; #endif if (this.kiiPushPlugin == null) { Debug.Log("#####failed to find KiiPushPlugin"); return; } this.kiiPushPlugin.RegisterPush((string pushToken, System.Exception e0) => { if (e0 != null) { Debug.Log("#####failed to RegisterPush: " + pushToken); return; } Debug.Log("#####RegistrationId= Token:" + pushToken); Debug.Log("#####Install"); KiiUser.PushInstallation(false).Install(pushToken, deviceType, (System.Exception e3) => { if (e3 != null) { Debug.Log("#####failed to Install"); this.ShowException("Failed to install PushNotification -- pushToken=" + pushToken, e3); return; } suscribeTopic("MainTopic"); String country_topic = PlayerPrefs.GetString("pais_locale"); if (country_topic != null && country_topic != "") { suscribeTopic(country_topic); } }); }); }
void registerPush() { #if UNITY_IPHONE KiiPushInstallation.DeviceType deviceType = KiiPushInstallation.DeviceType.IOS; #elif UNITY_ANDROID KiiPushInstallation.DeviceType deviceType = KiiPushInstallation.DeviceType.ANDROID; #else KiiPushInstallation.DeviceType deviceType = KiiPushInstallation.DeviceType.ANDROID; #endif if (this.kiiPushPlugin == null) { Debug.Log("#####failed to find KiiPushPlugin"); return; } this.kiiPushPlugin.RegisterPush((string pushToken, Exception e0) => { if (e0 != null) { Debug.Log("#####failed to RegisterPush"); this.message = "#####failed to RegisterPush : " + pushToken; return; } Debug.Log("#####RegistrationId=" + pushToken); this.message = "Token : " + pushToken + "\n"; Debug.Log("#####Install"); KiiUser.PushInstallation(true).Install(pushToken, deviceType, (Exception e3) => { if (e3 != null) { Debug.Log("#####failed to Install"); this.ShowException("Failed to install PushNotification -- pushToken=" + pushToken, e3); return; } KiiBucket bucket = KiiUser.CurrentUser.Bucket(BUCKET_NAME); Debug.Log("#####Subscribe"); String userId = KiiUser.CurrentUser.GetString("userID"); Debug.Log("#####https://api-jp.kii.com/api/apps/f39c2d34/users/" + userId + "/buckets/app_bucket/objects"); KiiUser.CurrentUser.PushSubscription.Subscribe(bucket, (KiiSubscribable subscribable, Exception e6) => { Debug.Log("#####callback Subscribe"); if (e6 != null) { if (e6 is ConflictException) { this.message += "Bucket is already subscribed" + "\n"; this.message += "Push is ready"; Debug.Log("#####all setup success!!!!!!"); return; } Debug.Log("#####failed to Subscribe"); this.ShowException("Failed to subscribe bucket", e6); return; } else { this.message += "Push is ready"; Debug.Log("#####all setup success!!!!!!"); } }); }); }); }
void Start() { count = 0; if (Kii.AppId != null) { user = KiiUser.CurrentUser; } //Set up push listeners KiiPushPlugin kiiPushPlugin = GameObject.Find("KiiPushPlugin").GetComponent <KiiPushPlugin> (); Debug.Log("Found KiiPushPlugin object in game objects"); kiiPushPlugin.OnPushMessageReceived += (ReceivedMessage message) => { // This event handler is called when received the push message. switch (message.PushMessageType) { case ReceivedMessage.MessageType.PUSH_TO_APP: Debug.Log("#####PUSH_TO_APP Message"); // do something to notify your app of the incomig message break; case ReceivedMessage.MessageType.PUSH_TO_USER: Debug.Log("#####PUSH_TO_USER Message"); // your user received a message, do something break; case ReceivedMessage.MessageType.DIRECT_PUSH: Debug.Log("#####DIRECT_PUSH Message"); // A direct push message was sent from developer.kii.com // Let's grab the url value of the message and open that page string url = message.GetString("url"); Debug.Log("Url in message is: " + url); Application.OpenURL("http://" + url); break; } Debug.Log("Type=" + message.PushMessageType); Debug.Log("Sender=" + message.Sender); Debug.Log("Scope=" + message.ObjectScope); // You can get the value of custom field using GetXXXX method. Debug.Log("Payload=" + message.GetString("payload")); }; #if UNITY_IPHONE KiiPushInstallation.DeviceType deviceType = KiiPushInstallation.DeviceType.IOS; #elif UNITY_ANDROID KiiPushInstallation.DeviceType deviceType = KiiPushInstallation.DeviceType.ANDROID; #else KiiPushInstallation.DeviceType deviceType = KiiPushInstallation.DeviceType.ANDROID; #endif kiiPushPlugin.RegisterPush((string pushToken, Exception e0) => { if (e0 != null) { Debug.Log("#####failed to RegisterPush"); return; } Debug.Log("#####RegistrationId=" + pushToken); Debug.Log("#####Install"); KiiUser.PushInstallation(true).Install(pushToken, deviceType, (Exception e3) => { if (e3 != null) { Debug.Log("#####failed to Install"); return; } }); }); }
void registerPush() { #if UNITY_IPHONE KiiPushInstallation.DeviceType deviceType = KiiPushInstallation.DeviceType.IOS; #elif UNITY_ANDROID KiiPushInstallation.DeviceType deviceType = KiiPushInstallation.DeviceType.ANDROID; #else KiiPushInstallation.DeviceType deviceType = KiiPushInstallation.DeviceType.ANDROID; #endif if (this.kiiPushPlugin == null) { Debug.Log("#####failed to find KiiPushPlugin"); return; } this.kiiPushPlugin.RegisterPush((string pushToken, Exception e0) => { if (e0 != null) { Debug.Log("#####failed to RegisterPush"); this.message = "#####failed to RegisterPush : " + pushToken; return; } Debug.Log("#####RegistrationId=" + pushToken); this.message = "Token : " + pushToken + "\n"; Debug.Log("#####Install"); KiiUser.PushInstallation(true).Install(pushToken, deviceType, (Exception e3) => { if (e3 != null) { Debug.Log("#####failed to Install"); this.ShowException("Failed to install PushNotification -- pushToken=" + pushToken, e3); return; } KiiTopic t = null; try { Debug.Log("#####Topic"); t = KiiUser.CurrentUser.Topic(TOPIC_NAME); } catch (Exception e) { Debug.Log("#####failed to create topic " + e.Message); } Debug.Log("#####Save"); t.Save((KiiTopic topic, Exception e4) => { Debug.Log("#####callback Save"); if (e4 != null && !(e4 is ConflictException)) { Debug.Log("#####failed to Save"); this.ShowException("Failed to save topic", e4); return; } if (e4 != null && e4 is ConflictException) { this.message += "Topic is already created" + "\n"; } Debug.Log("#####Subscribe"); KiiUser.CurrentUser.PushSubscription.Subscribe(topic, (KiiSubscribable subscribable, Exception e5) => { Debug.Log("#####callback Subscribe"); if (e5 != null) { if (e5 is ConflictException) { this.message += "Topic is already subscribed" + "\n"; this.message += "Push is ready"; Debug.Log("#####all setup success!!!!!!"); return; } Debug.Log("#####failed to Subscribe"); this.ShowException("Failed to subscribe topic", e5); return; } this.message += "Push is ready"; Debug.Log("#####all setup success!!!!!!"); }); }); }); }); }
void registerPush() { #if UNITY_IPHONE KiiPushInstallation.DeviceType deviceType = KiiPushInstallation.DeviceType.IOS; #elif UNITY_ANDROID KiiPushInstallation.DeviceType deviceType = KiiPushInstallation.DeviceType.ANDROID; #else KiiPushInstallation.DeviceType deviceType = KiiPushInstallation.DeviceType.ANDROID; #endif if (this.kiiPushPlugin == null) { Debug.Log("#####failed to find KiiPushPlugin"); return; } this.kiiPushPlugin.RegisterPush((string pushToken, Exception e0) => { if (e0 != null) { Debug.Log("#####failed to RegisterPush"); this.message = "#####failed to RegisterPush : " + pushToken; return; } Debug.Log("#####RegistrationId=" + pushToken); this.message = "Token : " + pushToken + "\n"; Debug.Log("#####Install"); KiiUser.PushInstallation(true).Install(pushToken, deviceType, (Exception e3) => { if (e3 != null) { Debug.Log("#####failed to Install"); this.ShowException("Failed to install PushNotification -- pushToken=" + pushToken, e3); return; } KiiBucket bucket = KiiUser.CurrentUser.Bucket(BUCKET_NAME); // bucket.Acl(BucketAction.CREATE_OBJECTS_IN_BUCKET).Subject(KiiAnyAuthenticatedUser.Get()).Save(ACLOperation.GRANT, (KiiACLEntry<KiiBucket, BucketAction> entry, Exception e5)=>{ // if (e5 != null) // { // Debug.Log ("#####Failed to grant acl to the bucket"); // this.ShowException("Failed to grant acl to the bucket", e5); // return; // } Debug.Log("#####Subscribe"); KiiUser.CurrentUser.PushSubscription.Subscribe(bucket, (KiiSubscribable subscribable, Exception e6) => { Debug.Log("#####callback Subscribe"); if (e6 != null) { if (e6 is ConflictException) { this.message += "Bucket is already subscribed" + "\n"; this.message += "Push is ready"; Debug.Log("#####all setup success!!!!!!"); return; } Debug.Log("#####failed to Subscribe"); this.ShowException("Failed to subscribe bucket", e6); return; } else { this.message += "Push is ready"; Debug.Log("#####all setup success!!!!!!"); } }); // }); }); }); }
void OnGUI() { gui.Label(10, 10, 500, 50, (current == APP_US ? "US:" : "JP:") + current.AppID); if (gui.Button(10, 55, 245, 100, "Switch APP to US")) { this.current = APP_US; KiiInitializeBehaviour.Instance.SwitchApp(this.current.AppID, this.current.AppKey, this.current.Site); this.message = string.Format("Switch APP to {0} : {1}\n", this.current.Site, this.current.AppID); } if (gui.Button(265, 55, 245, 100, "Switch APP to JP")) { this.current = APP_JP; KiiInitializeBehaviour.Instance.SwitchApp(this.current.AppID, this.current.AppKey, this.current.Site); this.message = string.Format("Switch APP to {0} : {1}\n", this.current.Site, this.current.AppID); } if (gui.Button(10, 160, 160, 100, "Create Random User")) { this.message = ""; string username = "******" + DateTime.Now.Ticks.ToString(); KiiUser user = KiiUser.BuilderWithName(username).Build(); user.Register("pa$$sword", (KiiUser u, Exception e1) => { if (e1 == null) { this.message = "SUCCESS:\nuser="******"Failed to register user", e1); } }); } if (gui.Button(180, 160, 160, 100, "Facebook Login")) { this.message = ""; var connector = this.gameObject.AddComponent <KiiSocialNetworkConnector> (); connector.LogIn(Provider.FACEBOOK, (KiiUser user, Provider provider, Exception exception) => { if (exception == null) { this.message = "SUCCESS:\nuser="******"Failed to login with social connector", exception); } // Destroy connector if required. Destroy(connector); }); } if (gui.Button(350, 160, 160, 100, "Show user info")) { this.message = ""; KiiUser u = KiiUser.CurrentUser; if (u == null) { this.message = "User is not logged in :P"; return; } this.message = "*** User tokens ***\n"; this.message += GetDictionaryContents(u.GetAccessTokenDictionary()); this.message += "\n*** Social tokens ***\n"; this.message += GetDictionaryContents(u.GetSocialAccessTokenDictionary()); } if (gui.Button(10, 265, 160, 100, "Create 5-Object\n(1 Object/sec)")) { this.message = ""; KiiUser u = KiiUser.CurrentUser; if (u == null) { this.message = "User is not logged in :P"; return; } StartCoroutine(CreateNewObjects(5)); } if (gui.Button(10, 370, 160, 100, string.Format("Create topic\n({0})", topicname))) { this.message = ""; KiiUser u = KiiUser.CurrentUser; if (u == null) { this.message = "User is not logged in :P"; return; } KiiTopic topic = u.Topic(topicname); topic.Save((KiiTopic retTopic, Exception retException) => { if (retException == null) { this.message = "SUCCESS:\ntopic=" + retTopic.Uri.ToString(); } else { this.ShowException("Failed to create topic", retException); } }); } if (gui.Button(180, 370, 160, 100, "Subscribe topic")) { this.message = ""; KiiUser u = KiiUser.CurrentUser; if (u == null) { this.message = "User is not logged in :P"; return; } KiiTopic topic = u.Topic(topicname); u.PushSubscription.Subscribe(topic, (KiiSubscribable retSub, Exception retException) => { if (retException == null) { this.message = "SUCCESS:\nsubscribed topic=" + ((KiiTopic)retSub).Uri.ToString(); } else { this.ShowException("Failed to subscribe topic", retException); } }); } if (gui.Button(350, 370, 160, 100, "Check topic existence")) { this.message = ""; KiiUser u = KiiUser.CurrentUser; if (u == null) { this.message = "User is not logged in :P"; return; } KiiTopic topic = u.Topic(topicname); try { bool retExists = topic.Exists(); this.message = "SUCCESS:\ntopic existence=" + retExists; } catch (Exception e) { this.ShowException("Failed to check topic existence", e); } } if (gui.Button(10, 480, 160, 100, "Install Push")) { this.message = ""; KiiUser u = KiiUser.CurrentUser; if (u == null) { this.message = "User is not logged in :P"; return; } #if UNITY_IPHONE bool development = true; KiiPushInstallation.DeviceType deviceType = KiiPushInstallation.DeviceType.IOS; #elif UNITY_ANDROID bool development = true; KiiPushInstallation.DeviceType deviceType = KiiPushInstallation.DeviceType.ANDROID; #else this.message = "Push feature does not support on this platform :P"; return; #endif this.kiiPushPlugin.RegisterPush((string pushToken, Exception e0) => { if (e0 != null) { this.ShowException("Failed to register push : " + this.kiiPushPlugin.SenderID, e0); return; } this.message = "Push token : " + pushToken; KiiUser.PushInstallation(development).Install(pushToken, deviceType, (Exception e1) => { if (e1 != null) { this.ShowException("Failed to install push", e1); } else { this.message += "SUCCESS:\ninstall push=" + pushToken; SavePushInformation(deviceType, pushToken); } }); }); } if (gui.Button(180, 480, 160, 100, "Uninstall Push")) { this.message = ""; KiiUser u = KiiUser.CurrentUser; if (u == null) { this.message = "User is not logged in :P"; return; } #if UNITY_IPHONE bool development = true; KiiPushInstallation.DeviceType deviceType = KiiPushInstallation.DeviceType.IOS; #elif UNITY_ANDROID bool development = true; KiiPushInstallation.DeviceType deviceType = KiiPushInstallation.DeviceType.ANDROID; #else this.message = "Push feature does not support on this platform :P"; return; #endif string pushToken = LoadPushInformation(deviceType); KiiUser.PushInstallation(development).Uninstall(pushToken, deviceType, (Exception e0) => { if (e0 != null) { this.ShowException("Failed to uninstall push", e0); return; } this.kiiPushPlugin.UnregisterPush((Exception e1) => { if (e1 != null) { this.ShowException("Failed to unregister push", e1); } else { this.message = "SUCCESS:\nuninstall push=" + pushToken; ClearPushInformation(deviceType); } }); }); } if (gui.Button(350, 480, 160, 100, "Send Push")) { this.message = ""; KiiUser u = KiiUser.CurrentUser; if (u == null) { this.message = "User is not logged in :P"; return; } KiiTopic topic = u.Topic(topicname); // Build a push message. KiiPushMessageData data = new KiiPushMessageData() .Put("message", "Hi, switch app :)"); KiiPushMessage message = KiiPushMessage.BuildWith(data).SendAppID(true).Build(); // Send the push message. topic.SendMessage(message, (KiiPushMessage retMessage, Exception retException) => { if (retException == null) { this.message = "SUCCESS:\nsend message=" + retMessage.ToString(); } else { this.ShowException("Failed to send message", retException); } }); } int messageHeight = 590; gui.Label(10, messageHeight, 500, screenHeight - messageHeight, this.message); }
private void register() { user = null; OnCallback = true; KiiUser built_user = KiiUser.BuilderWithName(username).Build(); built_user.Register(password, (KiiUser user2, Exception e) => { if (e == null) { #if UNITY_IPHONE bool development = true; // choose development/production for iOS string USER = username; string PASS = password; KiiPushInstallation.DeviceType deviceType = KiiPushInstallation.DeviceType.IOS; plugin = GameObject.Find("KiiPush").GetComponent <KiiPushPlugin>(); plugin.RegisterPush((string pushToken, Exception e0) => { Debug.Log("Token :" + pushToken); if (e0 == null) { KiiUser.LogIn(USER, PASS, (KiiUser kiiuser, Exception e1) => { if (e1 == null) { KiiUser.PushInstallation(development).Install(pushToken, deviceType, (Exception e2) => { Debug.Log("Push registration completed"); KiiUser user3 = KiiUser.CurrentUser; KiiBucket bucket = Kii.Bucket("FlappyDogHighScore"); KiiPushSubscription ps = user3.PushSubscription; ps.Subscribe(bucket, (KiiSubscribable target, Exception e3) => { if (e3 != null) { // check fail cause Debug.Log("Subscription Failed"); Debug.Log(e3.ToString()); } }); }); } else { Debug.Log("e1 error: " + e1.ToString()); }; }); } else { Debug.Log("e0 error: " + e0.ToString()); }; }); #endif user = user2; Debug.Log("Register completed"); } else { user = null; OnCallback = false; Debug.Log("Register failed : " + e.ToString()); } }); }