diff --git a/.gitignore b/.gitignore index 090a1f0..4318e6b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -.idea -.DS_Store +**/.idea +**/.DS_Store +**/xcuserdata diff --git a/empty-project/Assets/Plugins/Android/FirebaseAndroidImpl.cs b/empty-project/Assets/Plugins/Android/FirebaseAndroidImpl.cs index bacd20b..72576e6 100644 --- a/empty-project/Assets/Plugins/Android/FirebaseAndroidImpl.cs +++ b/empty-project/Assets/Plugins/Android/FirebaseAndroidImpl.cs @@ -172,6 +172,16 @@ public AuthData Auth { return new AuthData(token, uid, expiration); } } + + public void GoOffline () + { + GetJavaObject ().CallStatic ("goOffline"); + } + + public void GoOnline () + { + GetJavaObject ().CallStatic ("goOnline"); + } #endregion class CompletionListener : AndroidJavaProxy { diff --git a/empty-project/Assets/Plugins/Editor/FirebaseEditorImpl.cs b/empty-project/Assets/Plugins/Editor/FirebaseEditorImpl.cs index 1ca0bc4..48b45cf 100644 --- a/empty-project/Assets/Plugins/Editor/FirebaseEditorImpl.cs +++ b/empty-project/Assets/Plugins/Editor/FirebaseEditorImpl.cs @@ -105,6 +105,11 @@ private static extern void _FirebaseAuthWithOAuthToken (IntPtr firebase, string private static extern long _FirebaseGetAuthExpiration(IntPtr firebase); [DllImport ("FirebaseProxy")] private static extern void _FirebaseUnAuth(IntPtr firebase); + + [DllImport ("FirebaseProxy")] + private static extern void _FirebaseGoOffline(); + [DllImport ("FirebaseProxy")] + private static extern void _FirebaseGoOnline(); #endregion @@ -220,6 +225,16 @@ public AuthData Auth { _FirebaseGetAuthExpiration(GetEditorObject())); } } + + public void GoOffline () + { + _FirebaseGoOffline (); + } + + public void GoOnline () + { + _FirebaseGoOnline (); + } #endregion diff --git a/empty-project/Assets/Plugins/Firebase/IFirebase.cs b/empty-project/Assets/Plugins/Firebase/IFirebase.cs index b0a9354..3290627 100644 --- a/empty-project/Assets/Plugins/Firebase/IFirebase.cs +++ b/empty-project/Assets/Plugins/Firebase/IFirebase.cs @@ -41,4 +41,7 @@ public interface IFirebase : IQuery void UnAuth(); AuthData Auth { get; } + + void GoOffline (); + void GoOnline (); } diff --git a/empty-project/Assets/Plugins/iOS/Firebase.mm b/empty-project/Assets/Plugins/iOS/Firebase.mm index f97800f..bdaf850 100644 --- a/empty-project/Assets/Plugins/iOS/Firebase.mm +++ b/empty-project/Assets/Plugins/iOS/Firebase.mm @@ -269,6 +269,14 @@ void _FirebaseUnAuth( void* firebase) { [myFirebaseRef unauth]; } + void _FirebaseGoOffline() { + [Firebase goOffline]; + } + + void _FirebaseGoOnline() { + [Firebase goOnline]; + } + float _DataSnapshotGetFloatValue (void* datasnapshot) { FDataSnapshot *snapshotRef = (__bridge FDataSnapshot*) (datasnapshot); return [[snapshotRef value] floatValue]; diff --git a/empty-project/Assets/Plugins/iOS/FirebaseiOSImpl.cs b/empty-project/Assets/Plugins/iOS/FirebaseiOSImpl.cs index 85be4c4..e15f5f9 100644 --- a/empty-project/Assets/Plugins/iOS/FirebaseiOSImpl.cs +++ b/empty-project/Assets/Plugins/iOS/FirebaseiOSImpl.cs @@ -124,6 +124,12 @@ private static extern void _FirebaseAuthWithOAuthToken (IntPtr firebase, string [DllImport ("__Internal")] private static extern void _FirebaseUnAuth( IntPtr firebase); + [DllImport ("__Internal")] + private static extern void _FirebaseGoOffline(); + + [DllImport ("__Internal")] + private static extern void _FirebaseGoOnline(); + #endregion #region IFirebase implementation @@ -236,6 +242,16 @@ public AuthData Auth { } } + public void GoOffline () + { + _FirebaseGoOffline (); + } + + public void GoOnline () + { + _FirebaseGoOnline (); + } + #endregion [MonoPInvokeCallbackAttribute(typeof(OnAuthSuccessHandler))] diff --git a/source/.DS_Store b/source/.DS_Store deleted file mode 100644 index 414b79f..0000000 Binary files a/source/.DS_Store and /dev/null differ diff --git a/source/XCodePlugin/.DS_Store b/source/XCodePlugin/.DS_Store deleted file mode 100644 index e2d6cbc..0000000 Binary files a/source/XCodePlugin/.DS_Store and /dev/null differ diff --git a/source/XCodePlugin/JniFirebase.cpp b/source/XCodePlugin/JniFirebase.cpp index cdde91d..e45abfe 100644 --- a/source/XCodePlugin/JniFirebase.cpp +++ b/source/XCodePlugin/JniFirebase.cpp @@ -376,4 +376,22 @@ void JniFirebase::UnAuth() { env->CallVoidMethod(m_firebase, s_unAuth); } +jmethodID JniFirebase::s_goOffline = NULL; +void JniFirebase::GoOffline() { + auto env = getEnv(); + if (!GetStaticMethod(env, s_firebaseClass, "goOffline", "()V", + &s_goOffline)) { + return; + } + env->CallStaticVoidMethod(NULL, s_goOffline); +} +jmethodID JniFirebase::s_goOnline = NULL; +void JniFirebase::GoOnline() { + auto env = getEnv(); + if (!GetMethod(env, s_firebaseClass, "goOnline", "()V", + &s_goOnline)) { + return; + } + env->CallStaticVoidMethod(NULL, s_goOnline); +} diff --git a/source/XCodePlugin/JniFirebase.h b/source/XCodePlugin/JniFirebase.h index f7f8d6c..bd20812 100644 --- a/source/XCodePlugin/JniFirebase.h +++ b/source/XCodePlugin/JniFirebase.h @@ -55,6 +55,9 @@ class JniFirebase { uint64_t GetAuthExpiration(); void UnAuth(); + + static void GoOffline(); + static void GoOnline(); jobject getJniObject() { return m_firebase; @@ -123,7 +126,9 @@ class JniFirebase { static jmethodID s_firebaseGetAuth; - static jmethodID s_unAuth; + + static jmethodID s_goOffline; + static jmethodID s_goOnline; }; #endif /* defined(__XCodePlugin__JniFirebase__) */ diff --git a/source/XCodePlugin/JniHelper.h b/source/XCodePlugin/JniHelper.h index 5114997..bba15f1 100644 --- a/source/XCodePlugin/JniHelper.h +++ b/source/XCodePlugin/JniHelper.h @@ -156,6 +156,22 @@ bool GetMethod(JNIEnv* env, jclass clazz, const char* methodName, const char* me return (*pMethod) != NULL; } +inline +bool GetStaticMethod(JNIEnv* env, jclass clazz, const char* methodName, const char* methodSig, jmethodID* pMethod) { + if (!env) { + return false; + } + if (*pMethod) { + return true; + } + lock lock(g_lock); + if (*pMethod) { + return true; + } + *pMethod = env->GetStaticMethodID(clazz, methodName, methodSig); + return (*pMethod) != NULL; +} + const char* CallToString(JNIEnv* env, jobject localRef) ; const char* GetJNIExceptionDescription(JNIEnv* env, jthrowable exception ); diff --git a/source/XCodePlugin/Plugin.cpp b/source/XCodePlugin/Plugin.cpp index 8ce0781..19ca773 100644 --- a/source/XCodePlugin/Plugin.cpp +++ b/source/XCodePlugin/Plugin.cpp @@ -246,6 +246,18 @@ void _FirebaseUnAuth(void* firebase) { jniFirebase->UnAuth(); } +void _FirebaseGoOffline(void* firebase) { + if (!firebase) return; + JniFirebase* jniFirebase = (JniFirebase*) firebase; + jniFirebase->GoOffline(); +} + +void _FirebaseGoOnline(void* firebase) { + if (!firebase) return; + JniFirebase* jniFirebase = (JniFirebase*) firebase; + jniFirebase->GoOnline(); +} + float _DataSnapshotGetFloatValue (void* datasnapshot) { if (!datasnapshot) return 0; JniDataSnapshot* jniDataSnapshot = (JniDataSnapshot*)datasnapshot;