void HandleMailFinished(object sender, MFComposeResultEventArgs e) { UIApplication.SharedApplication.InvokeOnMainThread(delegate { if (e.Result == MFMailComposeResult.Sent) { // No action required } else if (e.Result == MFMailComposeResult.Cancelled) { // No action required } else if (e.Result == MFMailComposeResult.Failed) { INotification notificationService = (INotification)IPhoneServiceLocator.GetInstance().GetService("notify"); if (notificationService != null) { notificationService.StartNotifyAlert("Mail Error", "Failed to send mail.\n" + e.Error, "OK"); } } else if (e.Result == MFMailComposeResult.Saved) { INotification notificationService = (INotification)IPhoneServiceLocator.GetInstance().GetService("notify"); if (notificationService != null) { notificationService.StartNotifyAlert("Mail Alert", "Mail saved to draft.", "OK"); } } // method reviewed (15 April 2014). e.Controller.DismissViewController(true, null); // deprecated --> e.Controller.DismissModalViewController (true); }); }
public override void Call(string phoneNumber, CallType type) { if (CallType.Voice.Equals(type)) { using (var pool = new NSAutoreleasePool()) { StringBuilder filteredPhoneNumber = new StringBuilder(); if (phoneNumber != null && phoneNumber.Length > 0) { foreach (char c in phoneNumber) { if (Char.IsNumber(c) || c == '+' || c == '-' || c == '.') { filteredPhoneNumber.Append(c); } } } String textURI = "tel:" + filteredPhoneNumber.ToString(); var thread = new Thread(InitiateCall); thread.Start(textURI); } ; } else { INotification notificationService = (INotification)IPhoneServiceLocator.GetInstance().GetService("notify"); if (notificationService != null) { notificationService.StartNotifyAlert("Phone Alert", "The requested call type is not enabled or supported on this device.", "OK"); } } }
public override IIo GetIOService() { if (_ioService == null) { _ioService = (IIo)IPhoneServiceLocator.GetInstance().GetService("io"); } return(_ioService); }
public override INotification GetNotificationService() { if (_notificationService == null) { _notificationService = (INotification)IPhoneServiceLocator.GetInstance().GetService("notify"); } return(_notificationService); }
public override IFileSystem GetFileSystemService() { if (_fileSystemService == null) { _fileSystemService = (IFileSystem)IPhoneServiceLocator.GetInstance().GetService("file"); } return(_fileSystemService); }
public bool ShouldAutorotate() { try { IDisplay service = (IDisplay)IPhoneServiceLocator.GetInstance().GetService("system"); return(!service.IsOrientationLocked()); } catch (Exception ex) { SystemLogger.Log(SystemLogger.Module.PLATFORM, "Error trying to determine if application should autorotate", ex); } return(true); // by default }
public IPhoneNSUrlProtocol(NSUrlRequest request, NSCachedUrlResponse cachedResponse, INSUrlProtocolClient client) : base(request, cachedResponse, client) { //SystemLogger.Log (SystemLogger.Module.PLATFORM, "# IPhoneNSUrlProtocol - Init with Request"); serviceLocator = IPhoneServiceLocator.GetInstance(); serviceURIHandler = new IPhoneServiceURIHandler(serviceLocator); resourceURIHandler = new IPhoneResourceHandler(ApplicationSource.FILE); serviceInvocationManager = new ServiceInvocationManager(); }
public bool IsIPad() { IOperatingSystem iOS = (IOperatingSystem)IPhoneServiceLocator.GetInstance().GetService("system"); HardwareInfo hInfo = iOS.GetOSHardwareInfo(); if (hInfo != null && hInfo.Version != null && hInfo.Version.Contains("iPad")) { return(true); } return(false); }
public override QRType HandleQRCode(MediaQRContent mediaQRContent) { if (mediaQRContent != null && mediaQRContent.QRType != null) { INotification notificationService = (INotification)IPhoneServiceLocator.GetInstance().GetService("notify"); NSUrl param = new NSUrl(mediaQRContent.Text); switch (mediaQRContent.QRType) { case QRType.EMAIL_ADDRESS: if ((UIApplication.SharedApplication.CanOpenUrl(param)) && (MFMailComposeViewController.CanSendMail)) { UIApplication.SharedApplication.OpenUrl(param); } else if (notificationService != null) { notificationService.StartNotifyAlert("Mail Alert", "Sending of mail messages is not enabled or supported on this device.", "OK"); } break; case QRType.TEL: if (UIApplication.SharedApplication.CanOpenUrl(param)) { UIApplication.SharedApplication.OpenUrl(param); } else if (notificationService != null) { notificationService.StartNotifyAlert("Phone Alert", "Establishing voice calls is not enabled or supported on this device.", "OK"); } break; case QRType.URI: if (UIApplication.SharedApplication.CanOpenUrl(param)) { UIApplication.SharedApplication.OpenUrl(param); } else if (notificationService != null) { notificationService.StartNotifyAlert("Browser Alert", "The requested URL could not be automatically opened.", "OK"); } break; default: if (notificationService != null) { notificationService.StartNotifyAlert("QR Alert", "The QR Code " + mediaQRContent.QRType.ToString() + " cannot be processed automatically.", "OK"); } break; } return(mediaQRContent.QRType); } return(QRType.TEXT); }
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))); }
/// <summary> /// Plaies the NS URL. /// </summary> /// <returns> /// <c>true</c>, if NS URL was played, <c>false</c> otherwise. /// </returns> /// <param name='nsUrl'> /// Ns URL. /// </param> private bool PlayNSUrl(NSUrl nsUrl) { if (nsUrl != null) { if (playerController != null && this.State == MediaState.Playing) { // if player is already playing, stop it. Stop(); } // TODO check if we are paused on the same file or not, to re-start player data. if (playerController == null) { try { using (var pool = new NSAutoreleasePool()) { var thread = new Thread(ShowMediaPlayer); thread.Start(nsUrl); }; } catch (Exception) { SystemLogger.Log(SystemLogger.Module.PLATFORM, "Error trying to get media file [" + nsUrl + "]"); } } /* * if(playerController != null) { * // Start Playing. * bool playing = playerController.Play(); * if(playing) { * this.State = MediaState.Playing; * } * return playing; * } */ return(true); } else { INotification notificationService = (INotification)IPhoneServiceLocator.GetInstance().GetService("notify"); if (notificationService != null) { notificationService.StartNotifyAlert("Media Alert", "Media file cannot be reproduced on on this device.", "OK"); } return(false); } }
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); }
public static UIWebView generateWebView() { UIWebView webView = new UIWebView(); webView.ScalesPageToFit = true; webView.LoadStarted += delegate(object sender, EventArgs e) { UIApplication.SharedApplication.NetworkActivityIndicatorVisible = true; }; webView.LoadFinished += delegate(object sender, EventArgs e) { UIApplication.SharedApplication.NetworkActivityIndicatorVisible = false; // stop notify loading masks if any INotification notificationService = (INotification)IPhoneServiceLocator.GetInstance().GetService("notify"); notificationService.StopNotifyLoading(); }; return(webView); }
private void InitiateCall(object textURI) { UIApplication.SharedApplication.InvokeOnMainThread(delegate { NSUrl urlParam = new NSUrl((string)textURI); SystemLogger.Log(SystemLogger.Module.PLATFORM, "Make CALL using URL :" + urlParam.ToString()); if (UIApplication.SharedApplication.CanOpenUrl(urlParam)) { UIApplication.SharedApplication.OpenUrl(urlParam); } else { INotification notificationService = (INotification)IPhoneServiceLocator.GetInstance().GetService("notify"); if (notificationService != null) { notificationService.StartNotifyAlert("Phone Alert", "Establishing voice calls is not enabled or supported on this device.", "OK"); } } }); }
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)); } }
/// <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); }
public override bool SendEmail(EmailData emailData) { UIApplication.SharedApplication.InvokeOnMainThread(delegate { if (MFMailComposeViewController.CanSendMail) { SystemLogger.Log(SystemLogger.Module.PLATFORM, "device supports email send"); using (var pool = new NSAutoreleasePool()) { var thread = new Thread(ShowMailComposer); thread.Start(emailData); } ; } else { INotification notificationService = (INotification)IPhoneServiceLocator.GetInstance().GetService("notify"); if (notificationService != null) { notificationService.StartNotifyAlert("Mail Alert", "Sending of mail messages is not enabled or supported on this device.", "OK"); } } }); return(true); }
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); } }); }
private void ShowCameraView() { UIApplication.SharedApplication.InvokeOnMainThread(delegate { if (UIImagePickerController.IsSourceTypeAvailable(UIImagePickerControllerSourceType.Camera)) { UIImagePickerController imagePickerController = new UIImagePickerController(); imagePickerController.SourceType = UIImagePickerControllerSourceType.Camera; imagePickerController.FinishedPickingMedia += HandleCameraFinishedPickingMedia; imagePickerController.Canceled += HandleImagePickerControllerCanceled; IPhoneServiceLocator.CurrentDelegate.MainUIViewController().PresentModalViewController(imagePickerController, true); IPhoneServiceLocator.CurrentDelegate.SetMainUIViewControllerAsTopController(false); } else { INotification notificationService = (INotification)IPhoneServiceLocator.GetInstance().GetService("notify"); if (notificationService != null) { notificationService.StartNotifyAlert("Media Alert", "Camera is not available on this device.", "OK"); } } }); }
public IPhoneWKScriptMessageHandler() { serviceLocator = IPhoneServiceLocator.GetInstance(); serviceURIHandler = new IPhoneServiceURIHandler(serviceLocator); serviceInvocationManager = new ServiceInvocationManager(); }
private void ShowMailComposer(object emailObject) { SystemLogger.Log(SystemLogger.Module.PLATFORM, "ShowMailComposer... "); EmailData emailData = (EmailData)emailObject; UIApplication.SharedApplication.InvokeOnMainThread(delegate { MFMailComposeViewController vcMail = new MFMailComposeViewController(); // To if (emailData.ToRecipientsAsString.Length > 0) { vcMail.SetToRecipients(emailData.ToRecipientsAsString); } // Cc if (emailData.CcRecipientsAsString.Length > 0) { vcMail.SetCcRecipients(emailData.CcRecipientsAsString); } // Bcc if (emailData.BccRecipientsAsString.Length > 0) { vcMail.SetBccRecipients(emailData.BccRecipientsAsString); } // Subject if (emailData.Subject != null) { vcMail.SetSubject(emailData.Subject); } // Body bool IsHtml = "text/html".Equals(emailData.MessageBodyMimeType); if (emailData.MessageBody != null) { vcMail.SetMessageBody(emailData.MessageBody, IsHtml); } // Attachement if (emailData.Attachment != null) { foreach (AttachmentData attachment in emailData.Attachment) { try { NSData data = null; if (attachment.Data == null || attachment.Data.Length == 0) { IFileSystem fileSystemService = (IFileSystem)IPhoneServiceLocator.GetInstance().GetService("file"); string fullPath = Path.Combine(fileSystemService.GetDirectoryRoot().FullName, attachment.ReferenceUrl); data = NSData.FromFile(fullPath); if (attachment.FileName == null || attachment.FileName.Length == 0) { attachment.FileName = Path.GetFileName(attachment.ReferenceUrl); } } else { data = NSData.FromArray(attachment.Data); } if (data != null) { vcMail.AddAttachmentData(data, attachment.MimeType, attachment.FileName); } } catch (Exception e) { SystemLogger.Log(SystemLogger.Module.PLATFORM, "Error adding attachment to Mail Composer.", e); } } } vcMail.Finished += HandleMailFinished; // method reviewed (15 April 2014). vcMail.ModalPresentationStyle = UIModalPresentationStyle.FullScreen; IPhoneServiceLocator.CurrentDelegate.MainUIViewController().PresentViewController(vcMail, true, null); // deprecated --> IPhoneServiceLocator.CurrentDelegate.MainUIViewController ().PresentModalViewController (vcMail, true); }); }
void HandleImagePickerControllerFinishedPickingMedia(object sender, UIImagePickerMediaPickedEventArgs e) { UIApplication.SharedApplication.InvokeOnMainThread(delegate { if (popover != null && popover.PopoverVisible) { popover.Dismiss(true); popover.Dispose(); } else { IPhoneServiceLocator.CurrentDelegate.MainUIViewController().DismissModalViewController(true); } }); SystemLogger.Log(SystemLogger.Module.PLATFORM, "FinishedPickingMedia " + e.Info); MediaMetadata mediaData = new MediaMetadata(); mediaData.Type = MediaType.NotSupported; try { NSString mediaType = (NSString)e.Info.ValueForKey(UIImagePickerController.MediaType); UIImage image = (UIImage)e.Info.ValueForKey(UIImagePickerController.OriginalImage); object url = e.Info.ValueForKey(UIImagePickerController.ReferenceUrl); NSUrl nsReferenceUrl = new NSUrl(url.ToString()); if (image != null && mediaType != null && mediaType == "public.image") // "public.image" is the default UTI (uniform type) for images. { mediaData.Type = MediaType.Photo; string fileExtension = Path.GetExtension(nsReferenceUrl.Path.ToLower()); mediaData.MimeType = MediaMetadata.GetMimeTypeFromExtension(fileExtension); mediaData.Title = this.GetImageMediaTitle(nsReferenceUrl.AbsoluteString); NSData imageData = null; if (mediaData.MimeType == "image/png" || mediaData.MimeType == "image/gif" || mediaData.MimeType == "image/tiff") { imageData = image.AsPNG(); } else if (mediaData.MimeType == "image/jpeg" || mediaData.MimeType == "image/jpg") { 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); }
public string GetUserAgent() { IOperatingSystem iOS = (IOperatingSystem)IPhoneServiceLocator.GetInstance().GetService("system"); return(iOS.GetOSUserAgent()); }