예제 #1
0
        //(Android/iOS)-NCMBManager.onAnalyticsReceived-this.NCMBAnalytics
        internal static void TrackAppOpened(string _pushId)
        {
            //ネイティブから取得したpushIdからリクエストヘッダを作成
            if (_pushId != null && NCMBManager._token != null && NCMBSettings.UseAnalytics) {

                string deviceType = "";
                if (SystemInfo.operatingSystem.IndexOf ("Android") != -1) {
                    deviceType = "android";
                } else if (SystemInfo.operatingSystem.IndexOf ("iPhone") != -1) {
                    deviceType = "ios";
                }

                //RESTリクエストデータ生成
                Dictionary<string,object> requestData = new Dictionary<string,object> {
                    { "pushId", _pushId },
                    { "deviceToken", NCMBManager._token },
                    { "deviceType", deviceType }
                };

                var json = Json.Serialize (requestData);
                string url = CommonConstant.DOMAIN_URL + "/" + CommonConstant.API_VERSION + "/push/" + _pushId + "/openNumber";
                ConnectType type = ConnectType.POST;
                string content = json.ToString ();
                NCMBDebug.Log ("content:" + content);
                //ログを確認(通信前)
                NCMBDebug.Log ("【url】:" + url + Environment.NewLine + "【type】:" + type + Environment.NewLine + "【content】:" + content);
                // 通信処理
                NCMBConnection con = new NCMBConnection (url, type, content, NCMBUser._getCurrentSessionToken ());
                con.Connect (delegate(int statusCode, string responseData, NCMBException error) {
                    try {
                        NCMBDebug.Log ("【StatusCode】:" + statusCode + Environment.NewLine + "【Error】:" + error + Environment.NewLine + "【ResponseData】:" + responseData);
                    } catch (Exception e) {
                        error = new NCMBException (e);
                    }
                    return;
                });

                #if UNITY_IOS
                    #if UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7
                    NotificationServices.ClearRemoteNotifications ();
                    #else
                    UnityEngine.iOS.NotificationServices.ClearRemoteNotifications ();
                    #endif
                #endif

            }
        }
예제 #2
0
        internal static IEnumerator SendRequest(NCMBConnection connection, UnityWebRequest req, object callback)
        {
            NCMBException error = null;

            byte[] byteData     = new byte[32768];
            string json         = "";
            string responseCode = "";

            // 通信実行
            // yield return req.Send ();

            // 通信実行
                        #if UNITY_2017_2_OR_NEWER
            req.SendWebRequest();
                        #else
            req.Send();
                        #endif

            // タイムアウト処理
            float elapsedTime = 0.0f;
            float waitTime    = 0.2f;
            while (!req.isDone)
            {
                //elapsedTime += Time.deltaTime;
                elapsedTime += waitTime;
                if (elapsedTime >= REQUEST_TIME_OUT)
                {
                    req.Abort();
                    error = new NCMBException();
                    break;
                }
                //yield return new WaitForEndOfFrame ();
                yield return(new WaitForSeconds(waitTime));
            }

            // 通信結果判定
            if (error != null)
            {
                // タイムアウト
                error.ErrorCode    = "408";
                error.ErrorMessage = "Request Timeout.";
                                #if UNITY_2017_1_OR_NEWER
            }
            else if (req.isNetworkError)
            {
                                #else
            }
            else if (req.isError)
            {
                                #endif
                // 通信エラー
                error              = new NCMBException();
                error.ErrorCode    = req.responseCode.ToString();
                error.ErrorMessage = req.error;
            }
            else if (req.responseCode != 200 && req.responseCode != 201)
            {
                // mBaaSエラー
                error = new NCMBException();
                var jsonData = MiniJSON.Json.Deserialize(req.downloadHandler.text) as Dictionary <string, object>;
                error.ErrorCode    = jsonData ["code"].ToString();
                error.ErrorMessage = jsonData ["error"].ToString();
            }
            else
            {
                // 通信成功
                byteData = req.downloadHandler.data;
                json     = req.downloadHandler.text;
            }

            //check E401001 error
            if (error != null)
            {
                connection._checkInvalidSessionToken(error.ErrorCode);
            }

            // check response signature
            if (callback != null && !(callback is NCMBExecuteScriptCallback))
            {
                // スクリプト機能はレスポンスシグネチャ検証外
                responseCode = req.responseCode.ToString();
                string responsText = req.downloadHandler.text;
                if (callback is HttpClientFileDataCallback)
                {
                    // NCMBFileのGETではbyteでシグネチャ計算を行うよう空文字にする
                    responsText = "";
                }
                connection._checkResponseSignature(responseCode, responsText, req, ref error);
            }

            if (callback != null)
            {
                if (callback is NCMBExecuteScriptCallback)
                {
                    ((NCMBExecuteScriptCallback)callback)(byteData, error);
                }
                else if (callback is HttpClientCallback)
                {
                    ((HttpClientCallback)callback)((int)req.responseCode, json, error);
                }
                else if (callback is HttpClientFileDataCallback)
                {
                    ((HttpClientFileDataCallback)callback)((int)req.responseCode, byteData, error);
                }
            }
        }
예제 #3
0
        private static void _ncmbLogIn(string name, string password, string email, NCMBCallback callback)
        {
            string url = _getLogInUrl ();//URL作成
            ConnectType type = ConnectType.GET;
            //set username, password
            NCMBUser logInUser = new NCMBUser ();

            logInUser.Password = password;

            //nameがあればLogInAsync経由 無ければLogInWithMailAddressAsync経由、どちらも無ければエラー
            if (name != null) {
                logInUser.UserName = name;
            } else if (email != null) {
                logInUser.Email = email;
            } else {
                throw new NCMBException (new ArgumentException ("UserName or Email can not be null."));
            }

            string content = logInUser._toJSONObjectForSaving (logInUser.StartSave ());
            Dictionary<string, object> paramDic = (Dictionary<string, object>)MiniJSON.Json.Deserialize (content);
            url = _makeParamUrl (url + "?", paramDic);
            //ログを確認(通信前)
            NCMBDebug.Log ("【url】:" + url + Environment.NewLine + "【type】:" + type + Environment.NewLine + "【content】:" + content);
            //通信処理
            NCMBConnection con = new NCMBConnection (url, type, content, NCMBUser._getCurrentSessionToken ());
            con.Connect (delegate(int statusCode , string responseData, NCMBException error) {
                try {
                    NCMBDebug.Log ("【StatusCode】:" + statusCode + Environment.NewLine + "【Error】:" + error + Environment.NewLine + "【ResponseData】:" + responseData);
                    if (error != null) {
                        NCMBDebug.Log ("[DEBUG AFTER CONNECT] Error: " + error.ErrorMessage);
                    } else {
                        Dictionary<string, object> responseDic = MiniJSON.Json.Deserialize (responseData) as Dictionary<string, object>;
                        logInUser._handleFetchResult (true, responseDic);
                        //save Current user
                        _saveCurrentUser (logInUser);

                    }
                } catch (Exception e) {
                    error = new NCMBException (e);
                }
                if (callback != null) {
                    Platform.RunOnMainThread (delegate {
                        callback (error);
                    });
                }
                return;
            });
        }
예제 #4
0
 internal static void _requestPasswordReset(string email, NCMBCallback callback)
 {
     string url = _getRequestPasswordResetUrl ();//URL
     ConnectType type = ConnectType.POST;
     //set username, password
     NCMBUser pwresetUser = new NCMBUser ();
     pwresetUser.Email = email;
     string content = pwresetUser._toJSONObjectForSaving (pwresetUser.StartSave ());
     //ログを確認(通信前)
     NCMBDebug.Log ("【url】:" + url + Environment.NewLine + "【type】:" + type + Environment.NewLine + "【content】:" + content);
     //通信処理
     NCMBConnection con = new NCMBConnection (url, type, content, NCMBUser._getCurrentSessionToken ());
     con.Connect (delegate(int statusCode , string responseData, NCMBException error) {
         try {
             NCMBDebug.Log ("【StatusCode】:" + statusCode + Environment.NewLine + "【Error】:" + error + Environment.NewLine + "【ResponseData】:" + responseData);
             if (error != null) {
                 NCMBDebug.Log ("[DEBUG AFTER CONNECT] Error: " + error.ErrorMessage);
             } else {
                 NCMBDebug.Log ("[DEBUG AFTER CONNECT] Successful: ");
             }
         } catch (Exception e) {
             error = new NCMBException (e);
         }
         if (callback != null) {
             Platform.RunOnMainThread (delegate {
                 callback (error);
             });
         }
         return;
     });
 }
예제 #5
0
 internal static void _logOut(NCMBCallback callback)
 {
     string url = _getLogOutUrl ();//URL作成
     ConnectType type = ConnectType.GET;
     string content = null;
     //ログを確認(通信前)
     NCMBDebug.Log ("【url】:" + url + Environment.NewLine + "【type】:" + type + Environment.NewLine + "【content】:" + content);
     //通信処理
     NCMBConnection con = new NCMBConnection (url, type, content, NCMBUser._getCurrentSessionToken ());
     con.Connect (delegate(int statusCode , string responseData, NCMBException error) {
         try {
             NCMBDebug.Log ("【StatusCode】:" + statusCode + Environment.NewLine + "【Error】:" + error + Environment.NewLine + "【ResponseData】:" + responseData);
             if (error != null) {
                 NCMBDebug.Log ("[DEBUG AFTER CONNECT] Error: " + error.ErrorMessage);
             } else {
                 _logOutEvent ();
             }
         } catch (Exception e) {
             error = new NCMBException (e);
         }
         if (callback != null) {
             Platform.RunOnMainThread (delegate {
                 callback (error);
             });
         }
         return;
     });
 }
예제 #6
0
        /// <summary>
        /// 非同期処理で指定したメールアドレスに対して、<br/>
        /// 会員登録を行うためのメールを送信するよう要求します。<br/>
        /// 通信結果が必要な場合はコールバックを指定するこちらを使用します。
        /// </summary>
        /// <param name="email">メールアドレス</param>
        /// <param name="callback">コールバック</param>
        public static void RequestAuthenticationMailAsync(string email, NCMBCallback callback)
        {
            new AsyncDelegate (delegate {
                //URL
                string url = _getmailAddressUserEntryUrl ();//URL

                //コンテント
                NCMBUser user = new NCMBUser ();
                user.Email = email;
                string content = user._toJSONObjectForSaving (user.StartSave ());

                //Type
                ConnectType type = ConnectType.POST;

                NCMBConnection con = new NCMBConnection (url, type, content, NCMBUser._getCurrentSessionToken ());
                NCMBDebug.Log ("【url】:" + url + Environment.NewLine + "【type】:" + type + Environment.NewLine + "【content】:" + content);
                con.Connect (delegate(int statusCode , string responseData, NCMBException error) {
                    NCMBDebug.Log ("【StatusCode】:" + statusCode + Environment.NewLine + "【Error】:" + error + Environment.NewLine + "【ResponseData】:" + responseData);
                    if (callback != null) {
                        Platform.RunOnMainThread (delegate {
                            callback (error);
                        });
                    }
                    return;
                });
            }).BeginInvoke ((IAsyncResult r) => {
            }, null);
        }