public void InitializeWeakDelegate() { if (UIApplication.SharedApplication.WeakDelegate == null || !(UIApplication.SharedApplication.WeakDelegate is UIApplicationWeakDelegate)) { UIApplication.SharedApplication.WeakDelegate = new UIApplicationWeakDelegate(); SystemLogger.Log(SystemLogger.Module.PLATFORM, "******************************************* Registering UIApplicationWeakDelegate for the current UIApplication (push notifications module)"); } }
public static void FireUnityJavascriptEvent(string method, object data) { UIViewController viewController = UIApplication.SharedApplication.KeyWindow.RootViewController; JavaScriptSerializer Serialiser = new JavaScriptSerializer(); string dataJSONString = "null"; if (data != null) { dataJSONString = Serialiser.Serialize(data); if (data is String) { dataJSONString = "'" + (data as String) + "'"; } } string jsCallbackFunction = "if(" + method + "){" + method + "(" + dataJSONString + ");}"; //only for testing SystemLogger.Log(SystemLogger.Module.PLATFORM, "NotifyJavascript (single object): " + method + ", dataJSONString: " + dataJSONString); bool webViewFound = false; if (viewController != null && viewController.View != null) { UIView[] subViews = viewController.View.Subviews; foreach (UIView subView in subViews) { if (subView is UIWebView) { webViewFound = true; // evaluate javascript as a UIWebView (subView as UIWebView).EvaluateJavascript(jsCallbackFunction); } else if (subView is WKWebView) { webViewFound = true; // evaluate javascript as a WKWebView (subView as WKWebView).EvaluateJavaScript(new NSString(jsCallbackFunction), delegate(NSObject result, NSError error) { SystemLogger.Log(SystemLogger.Module.PLATFORM, "NotifyJavascript COMPLETED (" + method + ")"); }); } } } if (webViewFound) { SystemLogger.Log(SystemLogger.Module.PLATFORM, "NotifyJavascript EVALUATED (" + method + ")"); } else { SystemLogger.Log(SystemLogger.Module.PLATFORM, "It was not possible to find a WebView to evaluate the javascript method"); } }
public static String JSONSerialize(object data) { try { JavaScriptSerializer Serialiser = new JavaScriptSerializer(); return(Serialiser.Serialize(data)); } catch (Exception ex) { SystemLogger.Log(SystemLogger.Module.PLATFORM, "Error trying to serialize object to JSON.", ex); } return(null); }
public NSDictionary ConvertToNSDictionary(Dictionary <String, Object> dictionary) { NSMutableDictionary prunedDictionary = new NSMutableDictionary(); foreach (String key in dictionary.Keys) { Object dicValue = dictionary[key]; if (dicValue is Dictionary <String, Object> ) { prunedDictionary.Add(new NSString(key), ConvertToNSDictionary((dicValue as Dictionary <String, Object>))); } else { //SystemLogger.Log(SystemLogger.Module.PLATFORM, "***** key["+key+"] is instance of: " + dicValue.GetType().FullName); if (dicValue != null) { if (dicValue is String) { prunedDictionary.Add(new NSString(key), new NSString((dicValue as String))); } else if (dicValue is int) { prunedDictionary.Add(new NSString(key), new NSNumber((int)dicValue)); } else if (dicValue is Object[]) { prunedDictionary.Add(new NSString(key), ConvertToNSArray((Object[])dicValue)); } else if (dicValue is System.Collections.ArrayList) { prunedDictionary.Add(new NSString(key), ConvertToNSArray((dicValue as System.Collections.ArrayList).ToArray())); } else { SystemLogger.Log(SystemLogger.Module.PLATFORM, "*** exception parsing key[" + key + "] instance of: " + dicValue.GetType().FullName + ". No complex object are valid inside this dictionary"); } } } } return(prunedDictionary); }
public void WebViewLoadingFinished(UIApplicationState applicationState, NSDictionary options) { SystemLogger.Log(SystemLogger.Module.PLATFORM, "******************************************* Detected WebView Loading Finished (processing launch options, if any)"); UIApplicationWeakDelegate.processNotification(options, true, applicationState); }
private static void log(string message) { SystemLogger.Log(SystemLogger.Module.GUI, "Push Notifications - UIApplicationWeakDelegate: " + message); }