public void ShareNotes( ) { if (Note != null) { string htmlStream; string textStream; Note.GetNotesForEmail(out htmlStream, out textStream); ExportedNoteSource noteSource = new ExportedNoteSource( ); noteSource.HTMLStream = new NSString(htmlStream); noteSource.TextStream = new NSString(textStream); var items = new NSObject[] { noteSource }; UIActivityViewController shareController = new UIActivityViewController(items, null); // set the subject line in case the share to email string emailSubject = string.Format(MobileApp.Shared.Strings.MessagesStrings.Read_Share_Notes, NoteName); shareController.SetValueForKey(new NSString(emailSubject), new NSString("subject")); // if devices like an iPad want an anchor, set it if (shareController.PopoverPresentationController != null) { shareController.PopoverPresentationController.SourceView = Task.NavToolbar; } PresentViewController(shareController, true, null); } }
public void ShareLocalFile(TodoItem item) { try { var localFilePath = item.Image; var date = String.Format("{0:dddd, MMMM d, yyyy}", item.LastModified); var subject = $"Task from {date} with status {item.Status} "; var body = item.Content; if (string.IsNullOrWhiteSpace(localFilePath)) { Debug.WriteLine("ShareLocalFile Warning: localFilePath null or empty"); return; } var rootController = UIApplication.SharedApplication.KeyWindow.RootViewController; var sharedItems = new System.Collections.Generic.List <NSObject>(); var fileName = Path.GetFileName(localFilePath); ///File var fileUrl = NSUrl.FromFilename(localFilePath); sharedItems.Add(fileUrl); //Text var messageNSStr = new NSString(subject); sharedItems.Add(messageNSStr); //Text var messageBodyNSStr = new NSString(body); sharedItems.Add(messageBodyNSStr); UIActivity[] applicationActivities = null; var activityViewController = new UIActivityViewController(sharedItems.ToArray(), applicationActivities); // Subject if (!string.IsNullOrWhiteSpace("Share Task")) { activityViewController.SetValueForKey(NSObject.FromObject("Share Task"), new NSString("subject")); } if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) { activityViewController.PopoverPresentationController.SourceView = rootController.View; } rootController.PresentViewController(activityViewController, true, null); } catch (Exception ex) { if (ex != null && !string.IsNullOrWhiteSpace(ex.Message)) { Debug.WriteLine("ShareLocalFile Exception: {0}", ex.Message); } } }
public void ShareLocalFile(string localFilePath, string title = "", object view = null) { try { if (string.IsNullOrWhiteSpace(localFilePath)) { Console.WriteLine("Plugin.ShareFile: ShareLocalFile Warning: localFilePath null or empty"); return; } var window = UIApplication.SharedApplication.KeyWindow; var vc = window.RootViewController; while (vc.PresentedViewController != null) { vc = vc.PresentedViewController; } //var rootController = UIApplication.SharedApplication.KeyWindow.RootViewController; var sharedItems = new List <NSObject>(); var fileName = Path.GetFileName(localFilePath); var fileUrl = NSUrl.FromFilename(localFilePath); sharedItems.Add(fileUrl); UIActivity[] applicationActivities = null; var activityViewController = new UIActivityViewController(sharedItems.ToArray(), applicationActivities); // Subject if (!string.IsNullOrWhiteSpace(title)) { activityViewController.SetValueForKey(NSObject.FromObject(title), new NSString("subject")); } if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone) { vc.PresentViewController(activityViewController, true, null); } else { var shareView = view as UIView; if (shareView != null) { UIPopoverController popCont = new UIPopoverController(activityViewController); popCont.PresentFromRect(shareView.Frame, shareView, UIPopoverArrowDirection.Any, true); } else { throw new Exception("view is null: for iPad you must pass the view paramater. The view parameter should be the view that triggers the share action, i.e. the share button."); } } } catch (Exception ex) { if (ex != null && !string.IsNullOrWhiteSpace(ex.Message)) { Console.WriteLine("Exception in Plugin.ShareFile: ShareLocalFile Exception: {0}", ex); } } }
public void ShareLocalFile(string localFilePath, string title = "") { try { if (string.IsNullOrWhiteSpace(localFilePath)) { Console.WriteLine("Plugin.ShareFile: ShareLocalFile Warning: localFilePath null or empty"); return; } var rootController = UIApplication.SharedApplication.KeyWindow.RootViewController; var sharedItems = new System.Collections.Generic.List <NSObject>(); var fileName = Path.GetFileName(localFilePath); // Image //UIImage uiImage = UIImage.FromFile(localFilePath); //sharedItems.Add(uiImage); // File => Attachhment name incorrect //var fileData = NSData.FromFile(localFilePath); //sharedItems.Add(fileData); // var fileUrl = NSUrl.FromFilename(localFilePath); sharedItems.Add(fileUrl); //// Text //string theText = "the shared text message"; //var messageNSStr = new NSString(theText); //sharedItems.Add(messageNSStr); UIActivity[] applicationActivities = null; var activityViewController = new UIActivityViewController(sharedItems.ToArray(), applicationActivities); // Subject if (!string.IsNullOrWhiteSpace(title)) { activityViewController.SetValueForKey(NSObject.FromObject(title), new NSString("subject")); } rootController.PresentViewController(activityViewController, true, null); } catch (Exception ex) { if (ex != null && !string.IsNullOrWhiteSpace(ex.Message)) { Console.WriteLine("Plugin.ShareFile: ShareLocalFile Exception: {0}", ex); } } }
public static void Share(string title = null, string body = null, string url = null, UIBarButtonItem barButtonItem = null) { try { var activityItems = new List <NSObject>(); if (body != null) { activityItems.Add(new NSString(body)); } if (url != null) { activityItems.Add(new NSUrl(url)); } UIActivity[] applicationActivities = null; var activityController = new UIActivityViewController(activityItems.ToArray(), applicationActivities); if (title != null) { activityController.SetValueForKey(new NSString(title), new NSString("subject")); } if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) { var window = UIApplication.SharedApplication.KeyWindow; var pop = new UIPopoverController(activityController); if (barButtonItem != null) { pop.PresentFromBarButtonItem(barButtonItem, UIPopoverArrowDirection.Any, true); } else { var rect = new CGRect(window.RootViewController.View.Frame.Width / 2, window.RootViewController.View.Frame.Height / 2, 0, 0); pop.PresentFromRect(rect, window.RootViewController.View, UIPopoverArrowDirection.Any, true); } } else { var viewController = UIApplication.SharedApplication.KeyWindow.GetVisibleViewController(); viewController.PresentViewController(activityController, true, null); } } catch { } }
public void ShareLocalFile(string localFilePath, string title = "", object view = null) { try { if (string.IsNullOrWhiteSpace(localFilePath)) { Console.WriteLine("Plugin.ShareFile: ShareLocalFile Warning: localFilePath null or empty"); return; } var rootController = UIApplication.SharedApplication.KeyWindow.RootViewController; var sharedItems = new List <NSObject>(); var fileName = Path.GetFileName(localFilePath); var fileUrl = NSUrl.FromFilename(localFilePath); sharedItems.Add(fileUrl); UIActivity[] applicationActivities = null; var activityViewController = new UIActivityViewController(sharedItems.ToArray(), applicationActivities); // Subject if (!string.IsNullOrWhiteSpace(title)) { activityViewController.SetValueForKey(NSObject.FromObject(title), new NSString("subject")); } if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone) { rootController.PresentViewController(activityViewController, true, null); } else { // Tablet var popup = new UIPopoverController(activityViewController); UIView tabview = UIApplication.SharedApplication.KeyWindow.RootViewController.View; CGRect rect = new CGRect(tabview.Frame.Width / 2, tabview.Frame.Height, 50, 50); popup.PresentFromRect(rect, tabview, UIPopoverArrowDirection.Any, true); } } catch (Exception ex) { if (ex != null && !string.IsNullOrWhiteSpace(ex.Message)) { Console.WriteLine("Exception in Plugin.ShareFile: ShareLocalFile Exception: {0}", ex); } } }
public void ShareLocalFile(string localFilePath, string title = "", object view = null) { if (string.IsNullOrWhiteSpace(localFilePath)) { return; } var rootController = GetVisibleViewController();// UIApplication.SharedApplication.KeyWindow.RootViewController; var sharedItems = new List <NSObject>(); var fileName = Path.GetFileName(localFilePath); var fileUrl = NSUrl.FromFilename(localFilePath); sharedItems.Add(fileUrl); UIActivity[] applicationActivities = null; var activityViewController = new UIActivityViewController(sharedItems.ToArray(), applicationActivities); // Subject if (!string.IsNullOrWhiteSpace(title)) { activityViewController.SetValueForKey(NSObject.FromObject(title), new NSString("subject")); } if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone) { rootController.PresentViewController(activityViewController, true, null); } else { if (view is UIView shareView) { UIPopoverController popCont = new UIPopoverController(activityViewController); popCont.PresentFromRect(shareView.Frame, shareView, UIPopoverArrowDirection.Any, true); } else { throw new Exception("view is null: for iPad you must pass the view paramater. The view parameter should be the view that triggers the share action, i.e. the share button."); } } }
public void ShareVideo( ) { string noteString = MessagesStrings.Watch_Share_Header_Html + string.Format(MessagesStrings.Watch_Share_Body_Html, ShareUrl, Name); var items = new NSObject[] { new NSString(noteString) }; UIActivityViewController shareController = new UIActivityViewController(items, null); shareController.SetValueForKey(new NSString(MessagesStrings.Watch_Share_Subject), new NSString("subject")); shareController.ExcludedActivityTypes = new NSString[] { UIActivityType.PostToFacebook, UIActivityType.AirDrop, UIActivityType.PostToTwitter, UIActivityType.CopyToPasteboard, UIActivityType.Message }; // if devices like an iPad want an anchor, set it if (shareController.PopoverPresentationController != null) { shareController.PopoverPresentationController.SourceView = Task.NavToolbar; } PresentViewController(shareController, true, null); }
private void ShowActionSheet(string status, string title = "", string link = "") { link = link.Trim(); if (!string.IsNullOrWhiteSpace(link)) { var tempUri = new Uri(link); link = tempUri.GetLeftPart(UriPartial.Authority) + System.Web.HttpUtility.UrlPathEncode(tempUri.PathAndQuery); } var shareitem = new NSObject[] { new NSString(title), new NSUrl(link) }; var activityController = new UIActivityViewController(shareitem, null); activityController.SetValueForKey(new NSObject[] { new NSString(status) }.FirstOrDefault(), new NSString("subject")); //Would prefer this to popover from button on ipad if (activityController.PopoverPresentationController != null) { activityController.PopoverPresentationController.SourceView = UIApplication.SharedApplication.KeyWindow.RootViewController.ChildViewControllers != null ? UIApplication.SharedApplication.KeyWindow.RootViewController.ChildViewControllers[0].View : UIApplication.SharedApplication.KeyWindow.RootViewController.View; } UIApplication.SharedApplication.KeyWindow.RootViewController.ShowViewController(activityController, new NSObject()); }
public override void RowSelected(UITableView tableView, NSIndexPath indexPath) { tableView.DeselectRow(indexPath, true); switch (indexPath.Row) { case 0: // users.get CallMethod(VKApi.Users.Get(new NSMutableDictionary <NSString, NSObject> { { VKApiConst.Fields, (NSString)"first_name, last_name, uid, photo_100" }, { VKApiConst.UserId, (NSNumber)OwnerId } })); break; case 1: // friends.get CallMethod(VKApi.Friends.Get()); break; case 2: // friends.get with fields var friendsRequest = VKApi.Friends.Get(new NSMutableDictionary <NSString, NSObject> { { VKApiConst.Fields, (NSString)AllUserFields } }); CallMethod(friendsRequest); break; case 3: // subscribers CallMethod(VKRequest.Create <VKUsersArray> ("users.getFollowers", new NSMutableDictionary <NSString, NSObject> { { VKApiConst.UserId, (NSNumber)FollowersId }, { VKApiConst.Count, (NSNumber)100 }, { VKApiConst.Fields, (NSString)AllUserFields } })); break; case 4: // Upload photo to wall UploadWallPhoto(); break; case 5: // Upload photo to album UploadAlbumPhoto(); break; case 6: // Upload several photos to wall UploadSeveralWallPhotos(); break; case 7: // Test captcha var request = new VKApiCaptcha().Force(); request.Execute( resp => Console.WriteLine("Result: " + resp), error => Console.WriteLine("Error: " + error)); break; case 8: // Call unknown method CallMethod(VKRequest.Create("I.am.Lord.Voldemort", null)); break; case 9: // Test validation CallMethod(VKRequest.Create("account.testValidation", null)); break; case 10: // Test share dialog var shareDialog = new VKShareDialogController(); shareDialog.Text = "This post made with #vksdk #xamarin #ios"; shareDialog.Images = new [] { PhotoId, PhotoId2, PhotoId3 }; shareDialog.ShareLink = new VKShareLink("Super puper link, but nobody knows", new NSUrl("https://vk.com/dev/ios_sdk")); shareDialog.DismissAutomatically = true; PresentViewController(shareDialog, true, null); break; case 11: // Test VKActivity var items = new NSObject [] { UIImage.FromBundle("apple"), (NSString)"This post made with #vksdk activity #xamarin #ios", new NSUrl("https://vk.com/dev/ios_sdk") }; var activityViewController = new UIActivityViewController(items, new [] { new VKActivity() }); activityViewController.SetValueForKey((NSString)"VK SDK", (NSString)"subject"); activityViewController.CompletionHandler = null; if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) { var popover = activityViewController.PopoverPresentationController; if (popover != null) { popover.SourceView = View; popover.SourceRect = tableView.RectForRowAtIndexPath(indexPath); } } PresentViewController(activityViewController, false, null); break; case 12: // Test app request CallMethod(VKRequest.Create("apps.sendRequest", new NSMutableDictionary <NSString, NSObject> { { (NSString)"user_id", (NSNumber)FriendId }, { (NSString)"text", (NSString)"Yo ho ho" }, { (NSString)"type", (NSString)"request" }, { (NSString)"name", (NSString)"I need more gold" }, { (NSString)"key", (NSString)"more_gold" } })); break; } }
public void ShareVideo( ) { string noteString = MessagesStrings.Watch_Share_Header_Html + string.Format( MessagesStrings.Watch_Share_Body_Html, ShareUrl ); // if they set a mobile app url, add that. if( string.IsNullOrEmpty( MessagesStrings.Watch_Mobile_App_Url ) == false ) { noteString += string.Format( MessagesStrings.Watch_Share_DownloadApp_Html, MessagesStrings.Watch_Mobile_App_Url ); } var items = new NSObject[] { new NSString( noteString ) }; UIActivityViewController shareController = new UIActivityViewController( items, null ); shareController.SetValueForKey( new NSString( MessagesStrings.Watch_Share_Subject ), new NSString( "subject" ) ); shareController.ExcludedActivityTypes = new NSString[] { UIActivityType.PostToFacebook, UIActivityType.AirDrop, UIActivityType.PostToTwitter, UIActivityType.CopyToPasteboard, UIActivityType.Message }; // if devices like an iPad want an anchor, set it if ( shareController.PopoverPresentationController != null ) { shareController.PopoverPresentationController.SourceView = Task.NavToolbar; } PresentViewController( shareController, true, null ); }
public void ShareNotes() { if ( Note != null ) { string htmlStream; string textStream; Note.GetNotesForEmail( out htmlStream, out textStream ); ExportedNoteSource noteSource = new ExportedNoteSource(); noteSource.HTMLStream = new NSString( htmlStream ); noteSource.TextStream = new NSString( textStream ); var items = new NSObject[] { noteSource }; UIActivityViewController shareController = new UIActivityViewController( items, null ); // set the subject line in case the share to email string emailSubject = string.Format( App.Shared.Strings.MessagesStrings.Read_Share_Notes, NoteName ); shareController.SetValueForKey( new NSString( emailSubject ), new NSString( "subject" ) ); // if devices like an iPad want an anchor, set it if ( shareController.PopoverPresentationController != null ) { shareController.PopoverPresentationController.SourceView = Task.NavToolbar; } PresentViewController( shareController, true, null ); } }