public override void DetectWebViewLoadFinishedEvent(UIApplication application, NSDictionary launchOptions)
        {
            UIApplicationState applicationState = application.ApplicationState;

            ((UnityUI_iOSViewController_UIWebView)MainViewController()).webView.LoadFinished += delegate {
                                #if DEBUG
                log("************** WEBVIEW LOAD FINISHED");
                                #endif

                if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
                {
                    UIView.AnimationsEnabled = true;                      //enable again animation in all view  (see UnityUI_iOSViewController_UIWebView#loadWebView for details)
                }

                // inform other weak delegates (if exist) about the web view finished event
                IPhoneServiceLocator.WebViewLoadingFinished(applicationState, launchOptions);

                // The NSDictionary options variable would contain any notification data if the user clicked the 'view' button on the notification
                // to launch the application.
                // This method processes these options from the FinishedLaunching.
                processLaunchOptions(launchOptions, true, applicationState);

                // Processing extra data received when launched externally (using custom scheme url)
                processLaunchData();
            };
        }
Exemple #2
0
        /*
         * public override void DecidePolicy (WKWebView webView, WKNavigationAction navigationAction, Action<WKNavigationActionPolicy> decisionHandler)
         * {
         *      Console.WriteLine ("**** DecidePolicy****: " + navigationAction.Request);
         *
         *      webView.LoadRequest (navigationAction.Request);  // testing, it blocks the request load
         *
         * }
         */

        public override void DidFinishNavigation(WKWebView webView, WKNavigation navigation)
        {
                        #if DEBUG
            SystemLogger.Log(SystemLogger.Module.GUI, "AppverseWKNavigationDelegate ************** WEBVIEW LOAD FINISHED");
                        #endif
            if (_appDelegate != null && _application != null)
            {
                UIApplicationState applicationState = _application.ApplicationState;

                // inform other weak delegates (if exist) about the web view finished event
                IPhoneServiceLocator.WebViewLoadingFinished(applicationState, _launchOptions);

                // The NSDictionary options variable would contain any notification data if the user clicked the 'view' button on the notification
                // to launch the application.
                // This method processes these options from the FinishedLaunching.
                _appDelegate.processLaunchOptions(_launchOptions, true, applicationState);

                // Processing extra data received when launched externally (using custom scheme url)
                _appDelegate.processLaunchData();
            }
            else
            {
                                #if DEBUG
                SystemLogger.Log(SystemLogger.Module.GUI, "AppverseWKNavigationDelegate  ************** Application Delegate is not accessible. Stop processing notifications and/or launch data");
                                #endif
            }
        }
Exemple #3
0
        /// <summary>
        /// Open Socket listener on specific port
        /// </summary>
        protected void openSocketListener(int port)
        {
            try {
                                #if DEBUG
                log("[2] Opening Listener on port " + port + "...");
                                #endif
                if (httpServer == null)
                {
                    httpServer = new HttpServer(new Server(port));
                }
                socketOpened = true;

                                #if DEBUG
                log("[2] Listener OPENED on port: " + httpServer.Server.Port);
                                #endif

                // Adding Resource Handler.
                IPhoneResourceHandler resourceHandler = new IPhoneResourceHandler(ApplicationSource.FILE);
                //resourceHandler.Substitute = false;
                httpServer.Handlers.Add(resourceHandler);
                httpServer.Handlers.Add(new RemoteResourceHandler(IPhoneServiceLocator.GetInstance()));
            } catch (Exception ex) {
                                #if DEBUG
                log("[2] Cannot open internal server socket: " + ex.Message);
                                #endif
                if (ex.GetType() == typeof(System.Net.Sockets.SocketException))
                {
                    System.Net.Sockets.SocketException socketException = ex as System.Net.Sockets.SocketException;
                    //log ("[2] Socket exception: " + socketException.SocketErrorCode);
                    if (socketException.SocketErrorCode == System.Net.Sockets.SocketError.AddressAlreadyInUse)
                    {
                                                #if DEBUG
                        log("[2] Address already in use; trying with next port...");
                                                #endif
                        this.openSocketListener(port + 1);
                    }
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns>
        /// A <see cref="System.Boolean"/>
        /// </returns>
        protected bool openSocketListener(NSDictionary settings)
        {
            bool socketOpened = false;

            try {
                int defaultIPCPort = AppDelegate.GetIPCDefaultPort(settings);
                                #if DEBUG
                log("Opening Listener on port " + defaultIPCPort + "...");
                                #endif
                if (httpServer == null)
                {
                    httpServer = new HttpServer(new Server(defaultIPCPort));
                }
                socketOpened = true;

                                #if DEBUG
                log("Listener OPENED on port: " + httpServer.Server.Port);
                                #endif
                // Adding Resource Handler.
                IPhoneResourceHandler resourceHandler = new IPhoneResourceHandler(ApplicationSource.FILE);
                //resourceHandler.Substitute = false;
                httpServer.Handlers.Add(resourceHandler);

                // Adding Service URI Handler.
                httpServer.Handlers.Add(new IPhoneServiceURIHandler(IPhoneServiceLocator.GetInstance()));

                // Adding Remote Resource Handler.
                httpServer.Handlers.Add(new RemoteResourceHandler(IPhoneServiceLocator.GetInstance()));
            } catch (Exception ex) {
                                #if DEBUG
                log("Cannot open internal server socket: " + ex.Message);
                                #endif
            }

            return(socketOpened);
        }
Exemple #5
0
        private bool performSecurityChecks()
        {
            if (securityChecksPerfomed)
            {
                                #if DEBUG
                log("security checks already performed");
                                #endif
                return(securityChecksPassed);                // if security checks already performed, return
            }

                        #if DEBUG
            log("performing security checks...");
                        #endif

            //  initialize variable
            securityChecksPassed = false;

            if (blockRooted)
            {
                                #if DEBUG
                log("Checking device jailbroken (this app is not allowed to run in those devices)... ");
                                #endif

                ISecurity securityService  = (ISecurity)IPhoneServiceLocator.GetInstance().GetService("security");
                bool      IsDeviceModified = securityService.IsDeviceModified();

                if (IsDeviceModified)
                {
                                        #if DEBUG
                    log("Device is jailbroken. Application is blocked as per build configuration demand");
                                        #endif

                    UIApplication.SharedApplication.InvokeOnMainThread(delegate {
                                                #if DEBUG
                        log("Loading error page...");
                                                #endif
                        try {
                            // loading error page from file system
                            string basePath          = IPhoneUtils.GetInstance().GetDefaultBasePath();
                            string htmlErrorPageFile = "file://" + basePath + DEFAULT_LOCKED_HTML;

                            MainViewController().loadWebView(htmlErrorPageFile);
                        } catch (Exception ex) {
                                                        #if DEBUG
                            log("Unable to load error page on Appverse WebView. Exception message: " + ex.Message);
                                                        #endif
                        }
                    });

                    this.DismissSplashScreen();
                }
                else
                {
                    securityChecksPassed = true;
                                        #if DEBUG
                    log("Device is NOT jailbroken.");
                                        #endif
                }
            }
            else
            {
                securityChecksPassed = true;
                                #if DEBUG
                log("This app could be used in jailbroken devices");
                                #endif
            }

            securityChecksPerfomed = true;
            return(securityChecksPassed);
        }
Exemple #6
0
        /// <summary>
        /// Initializes the appverse context exposing data to the WebView Javascript DOM.
        /// </summary>
        private void InitializeAppverseContext()
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            try {
                                #if DEBUG
                log("Before loading the main HTML, platform will expose some information directly to javascript...");
                                #endif

                IPhoneSystem systemService = (IPhoneSystem)IPhoneServiceLocator.GetInstance().GetService("system");
                AbstractI18N i18nService   = (AbstractI18N)IPhoneServiceLocator.GetInstance().GetService("i18n");
                IIo          ioService     = (IIo)IPhoneServiceLocator.GetInstance().GetService("io");

                // 1. Appverse Context (Appverse.is)
                UnityContext unityContext           = systemService.GetUnityContext();
                String       unityContextJsonString = IPhoneUtils.GetInstance().JSONSerializeObjectData(unityContext);
                unityContextJsonString = "_AppverseContext = " + unityContextJsonString;
                this.EvaluateJavascript(unityContextJsonString);

                // 2. OS Info (Appverse.OSInfo)
                OSInfo osInfo           = systemService.GetOSInfo();
                String osInfoJsonString = IPhoneUtils.GetInstance().JSONSerializeObjectData(osInfo);
                osInfoJsonString = "_OSInfo = " + osInfoJsonString;
                this.EvaluateJavascript(osInfoJsonString);

                // 3. Hardware Info (Appverse.HardwareInfo)
                HardwareInfo hwInfo           = systemService.GetOSHardwareInfo();
                String       hwInfoJsonString = IPhoneUtils.GetInstance().JSONSerializeObjectData(hwInfo);
                hwInfoJsonString = "_HwInfo = " + hwInfoJsonString;
                this.EvaluateJavascript(hwInfoJsonString);

                // 4. Get all configured localized keys (Appverse.i18n)
                Unity.Core.I18N.Locale[] supportedLocales = i18nService.GetLocaleSupported();
                String localizedStrings = "_i18n = {};  _i18n['default'] = '" + i18nService.DefaultLocale + "'; ";
                String localeLiterals   = "";
                foreach (Unity.Core.I18N.Locale supportedLocale in supportedLocales)
                {
                    ResourceLiteralDictionary literals = i18nService.GetResourceLiterals(supportedLocale);
                    String literalsJsonString          = IPhoneUtils.GetInstance().JSONSerializeObjectData(literals);
                    localeLiterals = localeLiterals + " _i18n['" + supportedLocale.ToString() + "'] = " + literalsJsonString + "; ";
                }
                localizedStrings = localizedStrings + localeLiterals;
                this.EvaluateJavascript(localizedStrings);

                // 5. Current device locale
                Unity.Core.System.Locale currentLocale = systemService.GetLocaleCurrent();
                String currentLocaleJsonString         = IPhoneUtils.GetInstance().JSONSerializeObjectData(currentLocale);
                currentLocaleJsonString = "_CurrentDeviceLocale = " + currentLocaleJsonString;
                this.EvaluateJavascript(currentLocaleJsonString);

                // 6. Configured IO services endpoints
                IOService[] services           = ioService.GetServices();
                String      servicesJsonString = "_IOServices = {}; ";
                foreach (IOService service in services)
                {
                    String serviceJson = IPhoneUtils.GetInstance().JSONSerializeObjectData(service);
                    servicesJsonString = servicesJsonString + " _IOServices['" + service.Name + "-" + IPhoneUtils.GetInstance().JSONSerializeObjectData(service.Type) + "'] = " + serviceJson + "; ";
                }
                this.EvaluateJavascript(servicesJsonString);

                IPhoneNet NetService = (IPhoneNet)IPhoneServiceLocator.GetInstance().GetService("net");
                NetService.CheckConnectivity();
                String netJsonString = "_NetworkStatus = " + NetService.getNetStatus();
                this.EvaluateJavascript(netJsonString);
            } catch (Exception ex) {
                                #if DEBUG
                log("Unable to load Appverse Context. Exception message: " + ex.Message);
                                #endif
            }

            stopwatch.Stop();
                        #if DEBUG
            log("# Time elapsed initializing Appverse Context: " + stopwatch.Elapsed);
                        #endif
        }
        private bool performSecurityChecks()
        {
            if (securityChecksPerfomed)
            {
                                #if DEBUG
                log("security checks already performed");
                                #endif
                return(securityChecksPassed);                // if security checks already performed, return
            }

                        #if DEBUG
            log("performing security checks...");
                        #endif

            //  initialize variable
            securityChecksPassed = false;

            if (blockRooted)
            {
                                #if DEBUG
                log("Checking device jailbroken (this app is not allowed to run in those devices)... ");
                                #endif

                ISecurity securityService  = (ISecurity)IPhoneServiceLocator.GetInstance().GetService("security");
                bool      IsDeviceModified = securityService.IsDeviceModified();

                if (IsDeviceModified)
                {
                                        #if DEBUG
                    log("Device is jailbroken. Application is blocked as per build configuration demand");
                                        #endif

                    UIApplication.SharedApplication.InvokeOnMainThread(delegate {
                                                #if DEBUG
                        log("Loading error page...");
                                                #endif
                        try {
                            string htmlErrorPageFile  = IPhoneUtils.GetInstance().GetFileFullPath(DEFAULT_LOCKED_HTML);
                            byte[] htmlErrorPageBytes = IPhoneUtils.GetInstance().GetResourceAsBinary(htmlErrorPageFile, true);

                            NSData htmlErrorPageData = NSData.FromArray(htmlErrorPageBytes);
                            string mimeType          = "text/html";
                            string textEncodingName  = "UTF-8";

                            MainViewController().loadWebViewData(htmlErrorPageData, mimeType, textEncodingName, new NSUrl("/"));
                        } catch (Exception ex) {
                                                        #if DEBUG
                            log("Unable to load error page on Appverse WebView. Exception message: " + ex.Message);
                                                        #endif
                        }
                    });

                    this.DismissSplashScreen();
                }
                else
                {
                    securityChecksPassed = true;
                                        #if DEBUG
                    log("Device is NOT jailbroken.");
                                        #endif
                }
            }
            else
            {
                securityChecksPassed = true;
                                #if DEBUG
                log("This app could be used in jailbroken devices");
                                #endif
            }

            securityChecksPerfomed = true;
            return(securityChecksPassed);
        }