Call() public static method

Calls a method by name with the specified arguments. Returns a Method object. You must call yield return (Coroutine)instance; inside an IEnumerator/Coroutine function to actually execute the call. You can also call ExecuteAsync on the method instance to execute asynchronously outside of an IEnumerator.
public static Call ( string name ) : Method
name string Name of the method to call. Corresponds to the key in your Meteor.Methods({key: function value()}) statement.
return Method
Exemplo n.º 1
0
        static IEnumerator LoginWithDeviceCoroutine()
        {
            var loginMethod = Method <LoginUserResult> .Call("loginWithIDFV", SystemInfo.deviceUniqueIdentifier);

            loginMethod.OnResponse += HandleOnLogin;
            yield return((Coroutine)loginMethod);
        }
Exemplo n.º 2
0
        private static IEnumerator RegisterForPush()
        {
                        #if PUSH && UNITY_IOS
            UnityEngine.iOS.NotificationServices.RegisterForNotifications(UnityEngine.iOS.NotificationType.Alert | UnityEngine.iOS.NotificationType.Badge | UnityEngine.iOS.NotificationType.Sound);
            var deviceToken = UnityEngine.iOS.NotificationServices.deviceToken;

            while (deviceToken == null)
            {
                if (!string.IsNullOrEmpty(UnityEngine.iOS.NotificationServices.registrationError))
                {
                    yield break;
                }
                deviceToken = UnityEngine.iOS.NotificationServices.deviceToken;
                yield return(new WaitForEndOfFrame());
            }

            // Convert device token to hex
            var deviceTokenHex = new System.Text.StringBuilder(deviceToken.Length * 2);

            foreach (byte b in deviceToken)
            {
                deviceTokenHex.Append(b.ToString("X2"));
            }

            Debug.LogError(string.Format("deviceToken: {0}, Application.platform: {1}", deviceTokenHex, Application.platform.ToString()));

            var registerForPush = (Coroutine)Method.Call("registerForPush", Application.platform.ToString(), deviceTokenHex.ToString());
                        #else
            yield break;
                        #endif
        }
Exemplo n.º 3
0
        private static IEnumerator LoginWithFacebookCoroutine()
        {
                        #if FACEBOOK
            Error = null;
            var facebookHasInitialized = false;
            FB.Init(() => facebookHasInitialized = true);

            while (!facebookHasInitialized)
            {
                yield return(null);
            }


            FBResult loginResult = null;
            FB.Login("email", result => loginResult = result);

            while (loginResult == null)
            {
                yield return(null);
            }

            if (!FB.IsLoggedIn)
            {
                Response = null;
                Error    = new Error()
                {
                    error  = 500,
                    reason = "Could not login to Facebook."
                };
                yield break;
            }

            string meResultText  = null;
            string meResultError = null;
            var    meResult      = false;
            FB.API("/me", Facebook.HttpMethod.GET, result => {
                meResult      = true;
                meResultError = result.Error;
                meResultText  = result.Text;
            });

            while (!meResult)
            {
                yield return(null);
            }

            if (meResultText == null)
            {
                Response = null;
                Error    = new Error()
                {
                    error  = 500,
                    reason = meResultError
                };
                yield break;
            }

            var fbUser = meResultText.Deserialize <FacebookUser> ();

            var loginMethod = Method <LoginUserResult> .Call("facebookLoginWithAccessToken", FB.UserId, fbUser.email ?? string.Format("-{0}@facebook.com", FB.UserId), fbUser.name, FB.AccessToken);

            loginMethod.OnResponse += HandleOnLogin;
            yield return((Coroutine)loginMethod);
                        #else
            UnityEngine.Debug.LogError("Facebook login is not enabled with a build setting, or you're missing the Facebook SDK.");
            Error = new Error()
            {
                error  = 500,
                reason = "Facebook login is not enabled with a build setting, or you're missing the Facebook SDK."
            };
                        #endif

            yield break;
        }