private void sendMessage() { if (KiiUser.CurrentUser == null) { this.message = "#####KiiUser is not logged in!"; return; } KiiPushMessageData data = new KiiPushMessageData(); data.Put("payload", this.payload); data.Put("msg", "this message is sent from unity!!"); KiiPushMessage message = pushSetting.GetKiiPushMessage(data, apnsSetting, gcmSetting); KiiTopic topic = KiiUser.CurrentUser.Topic(TOPIC_NAME); topic.SendMessage(message, (KiiPushMessage target, Exception e) => { if (e != null) { Debug.Log("#####" + e.Message); Debug.Log("#####" + e.StackTrace); this.ShowException("Failed to send message", e); return; } this.message = "#####sending message is successful!!"; }); }
public KiiPushMessage GetKiiPushMessage(KiiPushMessageData data, APNSSetting apns, GCMSetting gcm) { return(KiiPushMessage.BuildWith(data) .EnableAPNS(EnableAPNS) .EnableGCM(EnableGCM) .SendAppID(SendAppID) .SendObjectScope(SendObjectScope) .SendOrigin(SendOrigin) .SendSender(SendSender) .SendToDevelopment(SendToDevelopment) .SendTopicId(SendTopicId) .SendToProduction(SendToProduction) .SendWhen(SendWhen) .WithAPNSMessage(apns.GetAPNSMessage()) .WithGCMMessage(gcm.GetGCMMessage()) .Build()); }
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); }