Example #1
0
        public override void RemoveStoredKeyValuePairs(string[] keynames)
        {
            string        sAccessGroup        = KeyChainAccessGroup;
            List <string> successfullKeyPairs = new List <string>();
            List <string> failedKeyPairs      = new List <string>();

            UIApplication.SharedApplication.InvokeOnMainThread(delegate {
                foreach (string keyname in keynames)
                {
                    SecRecord srDeleteEntry = new SecRecord(SecKind.GenericPassword)
                    {
                        Account = keyname
                    };

                    if (sAccessGroup != null)
                    {
                        srDeleteEntry.AccessGroup = sAccessGroup;
                    }

                    SecStatusCode code = SecKeyChain.Remove(srDeleteEntry);
                    if (code == SecStatusCode.Success)
                    {
                        successfullKeyPairs.Add(keyname);
                    }
                    else
                    {
                        failedKeyPairs.Add(keyname);
                    }
                }
                SystemLogger.Log(SystemLogger.Module.PLATFORM, "RemoveStoredKeyValuePair - Success: " + successfullKeyPairs.Count + ", Failed: " + failedKeyPairs.Count);

                IPhoneUtils.GetInstance().FireUnityJavascriptEvent("Appverse.OnKeyValuePairsRemoveCompleted", new object[] { successfullKeyPairs, failedKeyPairs });
            });
        }
Example #2
0
        private UILocalNotification PrepareLocalNotification(NotificationData notification)
        {
            if (notification != null)
            {
                UILocalNotification localNotification = new UILocalNotification();
                localNotification.AlertBody = notification.AlertMessage;
                localNotification.ApplicationIconBadgeNumber = notification.Badge;
                localNotification.SoundName = UILocalNotification.DefaultSoundName;                 // defaults
                if (notification.Sound != null && notification.Sound.Length > 0 && !notification.Sound.Equals("default"))
                {
                    // for sounds different from the default one
                    localNotification.SoundName = notification.Sound;
                }
                if (notification.CustomDataJsonString != null && notification.CustomDataJsonString.Length > 0)
                {
                    SystemLogger.Log(SystemLogger.Module.PLATFORM, "Custom Json String received: " + notification.CustomDataJsonString);

                    Dictionary <String, Object> userDictionary = (Dictionary <String, Object>)IPhoneUtils.GetInstance().JSONDeserialize <Dictionary <String, Object> >(notification.CustomDataJsonString);
                    localNotification.UserInfo = IPhoneUtils.GetInstance().ConvertToNSDictionary(userDictionary);
                }
                return(localNotification);
            }
            else
            {
                return(null);
            }
        }
Example #3
0
        protected override byte[] GetRawContentFromFileStream(string filePath)
        {
            SystemLogger.Log(SystemLogger.Module.PLATFORM, "# IPhoneResourceHandler. Getting Raw Content From FileStream on file path: " + filePath);

            // assuming that this method is just called for accessing web resources
            return(IPhoneUtils.GetInstance().GetResourceAsBinary(filePath, true));
        }
Example #4
0
 protected override ResourceLiteralDictionary readAllFromPlistFile(string file)
 {
     if (IPhoneUtils.GetInstance().ResourcesZipped)
     {
         // if resource is zipped, we will need to parse the file as an xml file (done in abstract class)
         return(base.readAllFromPlistFile(file));
     }
     else
     {
         ResourceLiteralDictionary result = null;
         if (this.FileExists(file))
         {
             result = new ResourceLiteralDictionary();
             NSDictionary literalDictionary = loadResourcesLiteral(file);
             foreach (NSObject key in literalDictionary.Keys)
             {
                 result.Add(key.ToString(), literalDictionary[key].ToString());
             }
             return(result);
         }
         else
         {
             // if file does not exists, means that requested locale is not supported by application
             // try then to get default locale string
             return(this.GetResourceLiterals());
         }
     }
 }
Example #5
0
 protected override string readFromPlistFile(string file, string key)
 {
     if (IPhoneUtils.GetInstance().ResourcesZipped)
     {
         // if resource is zipped, we will need to parse the file as an xml file (done in abstract class)
         return(base.readFromPlistFile(file, key));
     }
     else
     {
         string result = string.Empty;
         if (this.FileExists(file))
         {
             NSDictionary resourcesLiteral = loadResourcesLiteral(file);
             if (resourcesLiteral != null)
             {
                 result = getResourceLiteralValue(key, file, resourcesLiteral);
             }
             result = (result == null || result == string.Empty) ? String.Format("&lt;{0}&gt;", key) : result;
         }
         else
         {
             // if file does not exists, means that requested locale is not supported by application
             // try then to get default locale string
             return(this.GetResourceLiteral(key));
         }
         return(result);
     }
 }
Example #6
0
        private NSUrl GetNSUrlFromPath(string path, bool localPath)
        {
            NSUrl nsUrl = null;

            SystemLogger.Log(SystemLogger.Module.PLATFORM, "Getting nsurl from path: " + path);
            try {
                if (localPath)
                {
                    // check resource from local file system
                    //nsUrl = NSUrl.FromFilename(path);
                    nsUrl = IPhoneUtils.GetInstance().GetNSUrlFromPath(path);
                }
                else
                {
                    // check remote resource.
                    // remote paths should be escaped using Uri format
                    path  = Uri.EscapeUriString(path);
                    nsUrl = NSUrl.FromString(path);
                    SystemLogger.Log(SystemLogger.Module.PLATFORM, "nsUrl from remote string: " + nsUrl);
                }
            } catch (Exception) {
                SystemLogger.Log(SystemLogger.Module.PLATFORM, "Error trying to get media file [" + path + "]");
            }

            return(nsUrl);
        }
Example #7
0
        /// <summary>
        /// Updates the module.
        /// </summary>
        /// <param name="module">Module.</param>
        /// <param name="callbackId">An identifier to be returned on the event listener in order to identify this request.</param>
        public override void UpdateModule(Module module, string callbackId)
        {
            List <Module> successlist = new List <Module> ();
            List <Module> failedlist  = new List <Module> ();

            // show activity indicator
            this.GetNotificationService().StartNotifyActivity();
            this.GetNotificationService().StartNotifyLoading(this.GetLocalizedMessage(DEFAULT_LOADING_MESSAGE_UPDATE_MODULE));

            if (module != null)
            {
                bool success = this.UpdateOrInstallModule(module);
                if (success)
                {
                    SystemLogger.Log(SystemLogger.Module.PLATFORM, "The module [ " + module.Id + "] was successfully updated");
                    successlist.Add(module);
                }
                else
                {
                    SystemLogger.Log(SystemLogger.Module.PLATFORM, "The module [ " + module.Id + "] was NOT successfully updated");
                    failedlist.Add(module);
                }
            }

            UIApplication.SharedApplication.InvokeOnMainThread(delegate {
                IPhoneUtils.GetInstance().FireUnityJavascriptEvent("Appverse.AppLoader.onUpdateModulesFinished",
                                                                   new object [] { successlist.ToArray(), failedlist.ToArray(), callbackId });
            });

            // hide activity indicator
            this.GetNotificationService().StopNotifyActivity();
            this.GetNotificationService().StopNotifyLoading();
        }
Example #8
0
        public override void GetStoredKeyValuePairs(string[] keynames)
        {
            UIApplication.SharedApplication.InvokeOnMainThread(delegate {
                string sAccessGroup          = KeyChainAccessGroup;
                List <KeyPair> foundKeyPairs = new List <KeyPair>();
                foreach (string key in keynames)
                {
                    SecRecord srSearchCriteria = new SecRecord(SecKind.GenericPassword)
                    {
                        Account = key
                    };

                    if (sAccessGroup != null)
                    {
                        srSearchCriteria.AccessGroup = sAccessGroup;
                    }

                    SecStatusCode keyResult;
                    SecRecord srFoundKey = SecKeyChain.QueryAsRecord(srSearchCriteria, out keyResult);
                    if (keyResult == SecStatusCode.Success)
                    {
                        if (srFoundKey != null)
                        {
                            foundKeyPairs.Add(SecRecordToKeyPair(srFoundKey));
                        }
                    }
                }

                SystemLogger.Log(SystemLogger.Module.PLATFORM, "GetStoredKeyValuePairs - Found: " + foundKeyPairs.Count);

                IPhoneUtils.GetInstance().FireUnityJavascriptEvent("Appverse.OnKeyValuePairsFound", foundKeyPairs);
            });
        }
Example #9
0
        public override bool Play(string filePath)
        {
            // File path is relative path.
            string absolutePath = IPhoneUtils.GetInstance().GetFileFullPath(filePath);

            if (!File.Exists(absolutePath))
            {
                // file path was not under application bundle path
                // try to find it under Documents folder
                if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
                {
                    var documents = NSFileManager.DefaultManager.GetUrls(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User) [0].Path;
                    absolutePath = Path.Combine(documents, filePath);
                }
                else
                {
                    var documents = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                    absolutePath = Path.Combine(documents, filePath);
                };
                //absolutePath = Path.Combine(IPhoneFileSystem.DEFAULT_ROOT_PATH, filePath);
                SystemLogger.Log(SystemLogger.Module.PLATFORM, "Media file does not exist on bundle path, checking under application documents: " + absolutePath);
            }

            NSUrl nsUrl = this.GetNSUrlFromPath(absolutePath, true);

            return(this.PlayNSUrl(nsUrl));
        }
Example #10
0
 public bool ResourceExists(string resourcePath)
 {
     //SystemLogger.Log (SystemLogger.Module.PLATFORM, "# Checking file exists: " + resourcePath);
     if (this.ResourcesZipped)
     {
         return(IPhoneUtils.GetInstance().ResourceFromZippedExists(resourcePath));
     }
     else
     {
         return(File.Exists(resourcePath));
     }
 }
Example #11
0
 protected override XmlTextReader getXmlTextReader(string textFilePath)
 {
     if (IPhoneUtils.GetInstance().ResourcesZipped)
     {
         Stream stream = IPhoneUtils.GetInstance().GetResourceAsStream(textFilePath);
         return(new XmlTextReader(stream));
     }
     else
     {
         return(base.getXmlTextReader(textFilePath));
     }
 }
        public override void StoreKeyValuePairs(KeyPair[] keypairs)
        {
            string         sAccessGroup        = KeyChainAccessGroup;
            List <KeyPair> successfullKeyPairs = new List <KeyPair>();
            List <KeyPair> failedKeyPairs      = new List <KeyPair>();

            foreach (KeyPair kp in keypairs)
            {
                SecRecord srNewEntry = new SecRecord(SecKind.GenericPassword)
                {
                    Account   = kp.Key,
                    Generic   = NSData.FromString(kp.Key),
                    ValueData = NSData.FromString(kp.Value)
                };

                if (sAccessGroup != null)
                {
                    srNewEntry.AccessGroup = sAccessGroup;
                }

                SecStatusCode code = SecKeyChain.Add(srNewEntry);
                if (code == SecStatusCode.DuplicateItem)
                {
                    SecRecord srDeleteExistingEntry = new SecRecord(SecKind.GenericPassword)
                    {
                        Account = kp.Key
                    };
                    if (sAccessGroup != null)
                    {
                        srDeleteExistingEntry.AccessGroup = sAccessGroup;
                    }
                    code = SecKeyChain.Remove(srDeleteExistingEntry);
                    if (code == SecStatusCode.Success)
                    {
                        SecKeyChain.Add(srNewEntry);
                    }
                }
                if (code == SecStatusCode.Success)
                {
                    successfullKeyPairs.Add(kp);
                }
                else
                {
                    failedKeyPairs.Add(kp);
                }
            }

            SystemLogger.Log(SystemLogger.Module.PLATFORM, "StoreKeyValuePairs - Success: " + successfullKeyPairs.Count + ", Failed: " + failedKeyPairs.Count);
            UIApplication.SharedApplication.InvokeOnMainThread(delegate {
                IPhoneUtils.GetInstance().FireUnityJavascriptEvent("Unity.OnKeyValuePairsStoreCompleted", new object[] { successfullKeyPairs, failedKeyPairs });
            });
        }
Example #13
0
        protected override string GetContentFromStreamReader(string filePath)
        {
            //return base.GetContentFromStreamReader(filePath);
            SystemLogger.Log(SystemLogger.Module.PLATFORM, "# IPhoneResourceHandler. Getting Content From StreamReader on file path: " + filePath);

            Stream sr = IPhoneUtils.GetInstance().GetResourceAsStream(filePath);

            System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
            string content = enc.GetString(((MemoryStream)sr).GetBuffer());

            sr.Close();

            return(content);
        }
Example #14
0
        /// <summary>
        /// Deletes the modules.
        /// </summary>
        /// <param name="modules">Modules.</param>
        public override void DeleteModules(Module[] modules)
        {
            List <Module> successlist = new List <Module> ();
            List <Module> failedlist  = new List <Module> ();

            this.GetNotificationService().StartNotifyLoading(this.GetLocalizedMessage(DEFAULT_LOADING_MESSAGE_DELETE_MODULES));

            try {
                foreach (Module module in modules)
                {
                    bool moduleDeleted = false;
                    try {
                        string location      = this.GetModuleLocation(module, false);
                        string directoryName = Path.Combine(this.GetFileSystemService().GetDirectoryRoot().FullName, location);
                        SystemLogger.Log(SystemLogger.Module.PLATFORM, "Deleting module under: " + location);

                        if (Directory.Exists(directoryName))
                        {
                            Directory.Delete(directoryName, true);
                            moduleDeleted = true;
                        }
                        else
                        {
                            SystemLogger.Log(SystemLogger.Module.PLATFORM, "Module does not exists on filesystem. It couldn't be deleted.");
                        }
                    } catch (Exception ex) {
                        SystemLogger.Log(SystemLogger.Module.PLATFORM,
                                         "Exception when deleting module [" + (module != null?module.Id:"undefined") + "]: " + ex.Message);
                    }

                    if (moduleDeleted)
                    {
                        successlist.Add(module);
                    }
                    else
                    {
                        failedlist.Add(module);
                    }
                }
            } catch (Exception ex) {
                SystemLogger.Log(SystemLogger.Module.PLATFORM, "Exception when deleting modules: " + ex.Message);
            }
            UIApplication.SharedApplication.InvokeOnMainThread(delegate {
                IPhoneUtils.GetInstance().FireUnityJavascriptEvent("Appverse.AppLoader.onDeleteModulesFinished",
                                                                   new object [] { successlist.ToArray(), failedlist.ToArray() });
            });

            this.GetNotificationService().StopNotifyLoading();
        }
Example #15
0
        public override MediaMetadata GetMetadata(string filePath)
        {
            string absolutePath = filePath;
            bool   localPath    = false;

            if (!absolutePath.StartsWith("http"))
            {
                // File path is relative path
                absolutePath = IPhoneUtils.GetInstance().GetFileFullPath(filePath);
                localPath    = true;
            }
            NSUrl nsUrl = this.GetNSUrlFromPath(absolutePath, localPath);

            return(this.GetMetadataFromUrl(nsUrl));
        }
Example #16
0
 /// <summary>
 /// Sends the back result, by evaluating javascript inside UIWebview component (must be invoked on main thread)
 /// </summary>
 /// <param name='callbackFunction'>
 /// Callback function.
 /// </param>
 /// <param name='id'>
 /// Identifier.
 /// </param>
 /// <param name='jsonResultString'>
 /// Json result string.
 /// </param>
 protected override void SendBackResult(string callbackFunction, string id, string jsonResultString)
 {
     UIApplication.SharedApplication.InvokeOnMainThread(delegate {
         if (callbackFunction == null || callbackFunction.Equals("NULL"))
         {
             SystemLogger.Log(SystemLogger.Module.PLATFORM, " ############## There is no callback defined for sending back result to javascript app");
         }
         else
         {
             SystemLogger.Log(SystemLogger.Module.PLATFORM, " ############## sending back result to callback fn [" + callbackFunction + "] and id [" + id + "]: " +
                              (jsonResultString != null?jsonResultString.Length:0));
             IPhoneUtils.GetInstance().ExecuteJavascriptCallback(callbackFunction, id, jsonResultString);
         }
     });
 }
Example #17
0
 void HandleImagePickerControllerCanceled(object sender, EventArgs e)
 {
     UIApplication.SharedApplication.InvokeOnMainThread(delegate {
         SystemLogger.Log(SystemLogger.Module.PLATFORM, "Canceled picking image ");
         IPhoneUtils.GetInstance().FireUnityJavascriptEvent("Appverse.Media.onFinishedPickingImage", null);
         if (popover != null && popover.PopoverVisible)
         {
             popover.Dismiss(true);
             popover.Dispose();
         }
         else
         {
             IPhoneServiceLocator.CurrentDelegate.MainUIViewController().DismissModalViewController(true);
         }
     });
 }
        public NSData ProcessDocumentResource(string resourcePath)
        {
            SystemLogger.Log(SystemLogger.Module.PLATFORM, "# IPhoneResourceHandler. Processing document resource path: " + resourcePath);

            // url should be escaped to reach the real filesystem path for the requested file.
            resourcePath = Uri.UnescapeDataString(resourcePath);

            // Getting Root Directory for Files in this platform.
            IFileSystem   fileSystemService = (IFileSystem)IPhoneServiceLocator.GetInstance().GetService("file");
            DirectoryData rootDir           = fileSystemService.GetDirectoryRoot();

            resourcePath = Path.Combine(rootDir.FullName, resourcePath);

            // Get Resources as Binary Data and Write them to the server response
            return(NSData.FromArray(IPhoneUtils.GetInstance().GetResourceAsBinary(resourcePath, false)));
        }
Example #19
0
        /// <summary>
        /// Starts local authentication operation displaying Touch ID screen.
        /// </summary>
        /// <param name="reason">A reason to explain why authentication is needed. This helps to build trust with the user.</param>
        public override void StartLocalAuthenticationWithTouchID(string reason)
        {
            SystemLogger.Log(SystemLogger.Module.PLATFORM, "StartLocalAuthenticationWithTouchID - starting authentication using Touch ID...");
            UIApplication.SharedApplication.InvokeOnMainThread(delegate {
                SystemLogger.Log(SystemLogger.Module.PLATFORM, "StartLocalAuthenticationWithTouchID - checking Touch ID available in this device");

                bool available = this.CanEvaluatePolicy();
                if (available)
                {
                    SystemLogger.Log(SystemLogger.Module.PLATFORM, "StartLocalAuthenticationWithTouchID - start device owner authenticaiton using biometrics");
                    this.EvaluatePolicy(reason);
                }
                else
                {
                    IPhoneUtils.GetInstance().FireUnityJavascriptEvent("Appverse.Security.onTouchIDNotAvailable", null);
                }
            });
        }
Example #20
0
        void HandleCameraFinishedPickingMedia(object sender, UIImagePickerMediaPickedEventArgs e)
        {
            UIApplication.SharedApplication.InvokeOnMainThread(delegate {
                IPhoneServiceLocator.CurrentDelegate.MainUIViewController().DismissModalViewController(true);
            });

            SystemLogger.Log(SystemLogger.Module.PLATFORM, "Camera FinishedPickingMedia " + e.Info);

            MediaMetadata mediaData = new MediaMetadata();

            try {
                NSString mediaType = (NSString)e.Info.ValueForKey(UIImagePickerController.MediaType);
                UIImage  image     = (UIImage)e.Info.ValueForKey(UIImagePickerController.OriginalImage);

                if (image != null && mediaType != null && mediaType == "public.image")                 // "public.image" is the default UTI (uniform type) for images.
                {
                    mediaData.Type     = MediaType.Photo;
                    mediaData.MimeType = MediaMetadata.GetMimeTypeFromExtension(".jpg");
                    mediaData.Title    = (image.GetHashCode() & 0x7FFFFFFF) + ".JPG";

                    NSData imageData = image.AsJPEG();

                    if (imageData != null)
                    {
                        SystemLogger.Log(SystemLogger.Module.PLATFORM, "Getting image data raw data...");

                        byte[] buffer = new byte[imageData.Length];
                        Marshal.Copy(imageData.Bytes, buffer, 0, buffer.Length);

                        IFileSystem fileSystemService = (IFileSystem)IPhoneServiceLocator.GetInstance().GetService("file");
                        SystemLogger.Log(SystemLogger.Module.CORE, "Storing media file on application filesystem...");

                        mediaData.ReferenceUrl = fileSystemService.StoreFile(IPhoneMedia.ASSETS_PATH, mediaData.Title, buffer);
                    }

                    SystemLogger.Log(SystemLogger.Module.PLATFORM, mediaData.MimeType + ", " + mediaData.ReferenceUrl + ", " + mediaData.Title);
                }
            } catch (Exception ex) {
                SystemLogger.Log(SystemLogger.Module.PLATFORM, "Error when extracting information from media file: " + ex.Message, ex);
            }

            IPhoneUtils.GetInstance().FireUnityJavascriptEvent("Appverse.Media.onFinishedPickingImage", mediaData);
        }
Example #21
0
        public override bool Process(HttpServer server, HttpRequest request, HttpResponse response)
        {
            if (request.Url.StartsWith(DOCUMENTS_URI))
            {
                SystemLogger.Log(SystemLogger.Module.PLATFORM, " ############## " + this.GetType() + " -> " + request.Url);

                string requestUrl = request.Url;
                if (request.QueryString != null && request.QueryString.Length > 0)
                {
                    requestUrl = request.Page;
                    SystemLogger.Log(SystemLogger.Module.PLATFORM, " ############## " + this.GetType() + " -> removing req params -> " + requestUrl);
                }

                string escapedUrl = Uri.UnescapeDataString(requestUrl);
                // url should be escaped to reach the real filesystem path for the requested file.
                string resourcePath = escapedUrl.Substring(DOCUMENTS_URI.Length);

                // Getting mime type
                string ext  = Path.GetExtension(resourcePath.ToLower());
                string mime = (string)MimeTypes [ext];
                if (mime == null)
                {
                    mime = "application/octet-stream";
                }
                response.ContentType = mime;

                // Getting Root Directory for Files in this platform.
                IFileSystem   fileSystemService = (IFileSystem)IPhoneServiceLocator.GetInstance().GetService("file");
                DirectoryData rootDir           = fileSystemService.GetDirectoryRoot();
                resourcePath = Path.Combine(rootDir.FullName, resourcePath);

                // Get Resources as Binary Data and Write them to the server response
                response.RawContent = IPhoneUtils.GetInstance().GetResourceAsBinary(resourcePath, false);
                SystemLogger.Log(SystemLogger.Module.PLATFORM, " ############## " + this.GetType() + " -> file extension: " + ext + ", mimetype: " + mime + ", binary data length: " + response.RawContent.Length);

                return(true);
            }
            else
            {
                return(base.Process(server, request, response));
            }
        }
Example #22
0
        /// <summary>
        /// Method overrided, to start activity notification while invoking external service.
        /// </summary>
        /// <param name="request">
        /// A <see cref="IORequest"/>
        /// </param>
        /// <param name="service">
        /// A <see cref="IOService"/>
        /// </param>
        /// <returns>
        /// A <see cref="IOResponse"/>
        /// </returns>
        public override IOResponse InvokeService(IORequest request, IOService service)
        {
            this.IOUserAgent = IPhoneUtils.GetInstance().GetUserAgent();
            INotification notificationService = (INotification)IPhoneServiceLocator.GetInstance().GetService("notify");

            try {
                notificationService.StartNotifyActivity();
            } catch (Exception e) {
                SystemLogger.Log(SystemLogger.Module.PLATFORM, "Cannot StartNotifyActivity. Message: " + e.Message);
            }
            IOResponse response = base.InvokeService(request, service);

            try {
                notificationService.StopNotifyActivity();
            } catch (Exception e) {
                SystemLogger.Log(SystemLogger.Module.PLATFORM, "Cannot StopNotifyActivity. Message: " + e.Message);
            }

            return(response);
        }
Example #23
0
        private void ShowActionSheet(object sheet)
        {
            ActionSheet actionSheet = (ActionSheet)sheet;

            UIApplication.SharedApplication.InvokeOnMainThread(delegate {
                if (actionSheet.Title == null)
                {
                    actionSheet.Title = "";                     // null value cannot be passed to UIActionSheet constructor.
                }

                string cancelButton = null;
                string[] buttons    = new string[0];

                if (IPhoneUtils.GetInstance().IsIPad())
                {
                    // For iPad, cancelButton cannot be specified. It has to be included as an "other" button.
                    buttons = actionSheet.Buttons;
                }
                else
                {
                    if (actionSheet.Buttons != null && actionSheet.Buttons.Length > 0)
                    {
                        buttons      = new string[actionSheet.Buttons.Length - 1];
                        cancelButton = actionSheet.Buttons[0];
                        for (int i = 1; i < actionSheet.Buttons.Length; i++)
                        {
                            buttons[i - 1] = actionSheet.Buttons[i];
                        }
                    }
                    else
                    {
                        // default
                        cancelButton = "Cancel";
                    }
                }

                UIActionSheet uiSheet = new UIActionSheet(actionSheet.Title, new ActionSheetDelegate(actionSheet.JsCallbackFunctions), cancelButton, null, buttons);
                uiSheet.ShowInView(IPhoneServiceLocator.CurrentDelegate.MainUIViewController().View);
            });
        }
Example #24
0
        private void HandleLAContextReplyHandler(bool success, NSError error)
        {
            string message                   = success ? "EvaluatePolicy success" : string.Format("EvaluatePolicy: failed with error: {0}", error.LocalizedDescription);
            string errorDescription          = "Authentication Success";
            LocalAuthenticationStatus status = LocalAuthenticationStatus.Success;

            if (!success)
            {
                errorDescription = error.LocalizedDescription;
                switch (error.Code)
                {
                case 0:
                    status = LocalAuthenticationStatus.Success;
                    break;

                case -1:
                    status = LocalAuthenticationStatus.RetryExceeded;
                    break;

                case -2:
                    status = LocalAuthenticationStatus.UserCancel;
                    break;

                case -3:
                    status = LocalAuthenticationStatus.UserFallback;
                    break;

                default:
                    SystemLogger.Log(SystemLogger.Module.PLATFORM, "HandleLAContextReplyHandler - found not handled error code: " + error.Code);
                    break;
                }
            }

            SystemLogger.Log(SystemLogger.Module.PLATFORM, "HandleLAContextReplyHandler - " + message);

            UIApplication.SharedApplication.InvokeOnMainThread(delegate {
                IPhoneUtils.GetInstance().FireUnityJavascriptEvent("Appverse.Security.onLocalAuthenticationWithTouchIDReply", new object[] { status, errorDescription });
            });
        }
Example #25
0
        private void ShowImagePickerView()
        {
            UIApplication.SharedApplication.InvokeOnMainThread(delegate {
                UIImagePickerController imagePickerController = new UIImagePickerController();
                imagePickerController.FinishedPickingImage   += HandleImagePickerControllerFinishedPickingImage;
                imagePickerController.FinishedPickingMedia   += HandleImagePickerControllerFinishedPickingMedia;
                imagePickerController.Canceled += HandleImagePickerControllerCanceled;


                if (IPhoneUtils.GetInstance().IsIPad())
                {
                    try {
                        // in iPad, the UIImagePickerController should be presented inside a UIPopoverController, otherwise and exception is raised
                        popover     = new UIPopoverController(imagePickerController);
                        UIView view = IPhoneServiceLocator.CurrentDelegate.MainUIViewController().View;
                        //CGRect frame = new CGRect(new PointF(0,0),new SizeF(view.Frame.Size.Width, view.Frame.Size.Height));
                        CGRect frame = new CGRect(new PointF(0, 0), new SizeF(0, 0));
                        popover.PresentFromRect(frame, view, UIPopoverArrowDirection.Up, true);
                    }catch (Exception ex) {
                        INotification notificationService = (INotification)IPhoneServiceLocator.GetInstance().GetService("notify");
                        if (notificationService != null)
                        {
                            notificationService.StartNotifyAlert("Media Alert", "Unable to reach Photo Library", "OK");
                        }
                        if (popover != null && popover.PopoverVisible)
                        {
                            popover.Dismiss(true);
                            popover.Dispose();
                        }
                    }
                }
                else
                {
                    IPhoneServiceLocator.CurrentDelegate.MainUIViewController().PresentModalViewController(imagePickerController, true);
                }
            });
        }
Example #26
0
        public override void DetectQRCode(bool autoHandleQR)
        {
            String returnValue = String.Empty;

            UIApplication.SharedApplication.InvokeOnMainThread(delegate {
                MobileBarcodeScanner scanner = new MobileBarcodeScanner(IPhoneServiceLocator.CurrentDelegate.MainUIViewController());
                scanner.Scan().ContinueWith(t => {
                    if (t.Result != null)
                    {
                        MediaQRContent resultQRContent = new MediaQRContent(t.Result.Text, ZxingToBarcode(t.Result.BarcodeFormat), getQRTypeFromCode(t.Result));
                        //SystemLogger.Log(SystemLogger.Module.PLATFORM, "QR CODE returnValue: " + resultQRContent);

                        UIApplication.SharedApplication.InvokeOnMainThread(delegate {
                            IPhoneUtils.GetInstance().FireUnityJavascriptEvent("Unity.Media.onQRCodeDetected", resultQRContent);
                            if (autoHandleQR)
                            {
                                HandleQRCode(resultQRContent);
                            }
                        });
                    }
                });
                IPhoneServiceLocator.CurrentDelegate.SetMainUIViewControllerAsTopController(false);
            });
        }
Example #27
0
 /// <summary>
 /// Files the exists. Uses IPhoneUtils class to check if a file exists (could be zipped or not)
 /// </summary>
 /// <returns>
 /// <c>true</c>, if exists was filed, <c>false</c> otherwise.
 /// </returns>
 /// <param name='resourcePath'>
 /// Resource path.
 /// </param>
 public override bool FileExists(string resourcePath)
 {
     return(IPhoneUtils.GetInstance().ResourceExists(resourcePath));
 }
Example #28
0
 /// <summary>
 /// Method overrided, to use NSData to get stream from file resource inside application.
 /// </summary>
 /// <returns>
 /// A <see cref="Stream"/>
 /// </returns>
 public override byte[] GetConfigFileBinaryData()
 {
     return(IPhoneUtils.GetInstance().GetResourceAsBinary(this.SecurityConfigFile, true));
 }
 /// <summary>
 /// Gets the Directory Resources path.
 /// </summary>
 /// <returns>
 /// A <see cref="DirectoryData"/>
 /// </returns>
 public override DirectoryData GetDirectoryResources()
 {
     return(new DirectoryData(IPhoneUtils.GetInstance().GetFileFullPath(DEFAULT_RESOURCES_PATH)));
 }
Example #30
0
        public override void StoreKeyValuePairs(KeyPair[] keypairs)
        {
            string         sAccessGroup        = KeyChainAccessGroup;
            List <KeyPair> successfullKeyPairs = new List <KeyPair>();
            List <KeyPair> failedKeyPairs      = new List <KeyPair>();

            foreach (KeyPair kp in keypairs)
            {
                SecRecord srNewEntry = new SecRecord(SecKind.GenericPassword)
                {
                    Account   = kp.Key,
                    Generic   = NSData.FromString(kp.Key),
                    ValueData = NSData.FromString(kp.Value)
                };

                if (sAccessGroup != null)
                {
                    srNewEntry.AccessGroup = sAccessGroup;
                }


                if (this.GetPasscodeProtectedKeys().Contains(kp.Key))
                {
                    if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
                    {
                        SystemLogger.Log(SystemLogger.Module.PLATFORM,
                                         "StoreKeyValuePairs - Passcode protection applied to this keychain item (as configured in security-config.xml)");
                        srNewEntry.AccessControl = new SecAccessControl(SecAccessible.WhenPasscodeSetThisDeviceOnly, SecAccessControlCreateFlags.UserPresence);
                    }
                    else
                    {
                        SystemLogger.Log(SystemLogger.Module.PLATFORM,
                                         "StoreKeyValuePairs - Passcode protection is requested for this keychain item, but protection couldn't be applied due to device is iOS<8");
                    }
                }

                SecStatusCode code = SecKeyChain.Add(srNewEntry);
                if (code == SecStatusCode.DuplicateItem)
                {
                    SecRecord srDeleteExistingEntry = new SecRecord(SecKind.GenericPassword)
                    {
                        Account = kp.Key
                    };
                    if (sAccessGroup != null)
                    {
                        srDeleteExistingEntry.AccessGroup = sAccessGroup;
                    }
                    code = SecKeyChain.Remove(srDeleteExistingEntry);
                    if (code == SecStatusCode.Success)
                    {
                        SecKeyChain.Add(srNewEntry);
                    }
                }
                if (code == SecStatusCode.Success)
                {
                    successfullKeyPairs.Add(kp);
                }
                else
                {
                    failedKeyPairs.Add(kp);
                }
            }

            SystemLogger.Log(SystemLogger.Module.PLATFORM, "StoreKeyValuePairs - Success: " + successfullKeyPairs.Count + ", Failed: " + failedKeyPairs.Count);
            UIApplication.SharedApplication.InvokeOnMainThread(delegate {
                IPhoneUtils.GetInstance().FireUnityJavascriptEvent("Appverse.OnKeyValuePairsStoreCompleted", new object[] { successfullKeyPairs, failedKeyPairs });
            });
        }