how to create small task bar (Reply, Copy, Forword and Delete) in uitableviewcell like whatsapp when the message on press?
"UIMenuController" with "menuItems:" will be useful for your custom Actions.
Apple Documentation Link : https://developer.apple.com/reference/uikit/uimenucontroller
thank Ios Developer for your direction.. i already use "UIMenuController", but this menu is not shown.
my code:
[Export("LongPressMethod:")]
public void LongPressMethod(UILongPressGestureRecognizer gestureRecognizer)
{
if (gestureRecognizer.State == UIGestureRecognizerState.Began)
{
var menuController = UIMenuController.SharedMenuController;
var copyMenuItem = new UIMenuItem("copy", new ObjCRuntime.Selector("CopyRow"));
var pasteMenuItem = new UIMenuItem("paste", new ObjCRuntime.Selector("PasteRow"));
var location = gestureRecognizer.LocationInView(bc);
bc.BecomeFirstResponder();
menuController.MenuItems = new[] { copyMenuItem, pasteMenuItem };
menuController.SetTargetRect(new CGRect(location.X, location.Y, 100, 100), bc);
menuController.SetMenuVisible(true, true);
}
}
[Export("CopyRow:")]
void Row(UIMenuController controller)
{
// do something
}
[Export("PasteRow:")]
void PasteRow(UIMenuController controller)
{
// do something
}
Related
I am trying to implement Stripe in Xamarin forms with Apply Pay
I am following the following tutorial but I am stuck at one problem I can't find the STPApplePayContext class in Xamarin
The Library I am using
IOS Bindings or Xamarin.Stripe.iOS
Both provide iOS binidngs for Stripe.
Now as I am following the tutorial I can't find the STPApplePayContext in any of those Libs or something similar.
My code with iOS Bindings
public Task<bool> InitializeAsync(string clientToken)
{
// STPPaymentConfiguration
StripeSdk.STPPaymentConfiguration.SharedConfiguration().PublishableKey =
"pk_test_123456";
_canPay = Stripe_ApplePay.DeviceSupportsApplePay;
return Task.FromResult(true);
}
public bool CreatePaymentRequest(double amount)
{
_paymentRequest = _stripe.PaymentRequestWithMerchantIdentifier(_merchantID,"US","USD");
_paymentRequest.SupportedNetworks = _paymentNetworks;
_paymentRequest.MerchantCapabilities = PKMerchantCapability.ThreeDS;
_paymentRequest.PaymentSummaryItems = new[]
{
new PKPaymentSummaryItem()
{
Label = "Item",
Amount = new NSDecimalNumber(amount)
}
};
return true;
}
public bool Pay()
{
// var applePayContext = STPApplePayContext;
// if (applePayContext)
// {
// }
// if let applePayContext = STPApplePayContext(paymentRequest: paymentRequest, delegate: self) {
// // Present Apple Pay payment sheet
// applePayContext.presentApplePay(on: self)
// } else {
// // There is a problem with your Apple Pay configuration
// }
}
Can anybody point me in the right direction?
I am using the below code to share the files to other apps using xamarin iOS. but i didnt get any response. Is there any other option to share files to other apps using Xamarin iOS?
Ref: http://xamarinhelp.com/share-dialog-xamarin-forms/
public async Task Show(string title, string message, string filePath)
{
var items = new NSObject[] { NSObject.FromObject(title), NSUrl.FromFilename(filePath) };
var activityController = new UIActivityViewController(items, null);
var vc = GetVisibleViewController();
NSString[] excludedActivityTypes = null;
if (excludedActivityTypes != null && excludedActivityTypes.Length > 0)
activityController.ExcludedActivityTypes = excludedActivityTypes;
if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
{
if (activityController.PopoverPresentationController != null)
{
activityController.PopoverPresentationController.SourceView = vc.View;
}
}
await vc.PresentViewControllerAsync(activityController, true);
}
UIViewController GetVisibleViewController()
{
var rootController = UIApplication.SharedApplication.KeyWindow.RootViewController;
if (rootController.PresentedViewController == null)
return rootController;
if (rootController.PresentedViewController is UINavigationController)
{
return ((UINavigationController)rootController.PresentedViewController).TopViewController;
}
if (rootController.PresentedViewController is UITabBarController)
{
return ((UITabBarController)rootController.PresentedViewController).SelectedViewController;
}
return rootController.PresentedViewController;
}
I am trying to add Instagram in "Share To" functionality in my app. I have seen the Instagram's iPhone hooks documents. I have created custom UIActivty which works fine but my question is, is there a way to add "Import with Instagram" functionality as it can be seen in iOS's Photos app iOS Photo App:
In my app for some reason, it does not show that "Import with Instagram". my app Share view :
I do not want to share only with Instagram so no ".igo"
EDIT: All of this is specifically for iOS versions < 10. For some reasons Instagram Share Extension works fine (for my app) in devices with iOS >= 10.
EDIT: I am trying to share image and video with ".jpeg" and ".mov" formats respectively
I have seen/read that Instagram added share extension in release 8.2, so technically all the apps should show "Instagram" in share tray, i.e. it can be seen in Google Photos app.
public void NativeShareImage(UIView sourceView, CGRect sourceRect,
UIImage image, string shareCaption, string emailSubject)
{
string filename = Path.Combine(FileSystemUtils.GetTemporaryDataPath(), "Image.jpg");
NSError err = null;
using(var imgData = image.AsJPEG(JpgImageQuality))
{
if(imgData.Save(filename, false, out err))
{
Logger.Information("Image saved before native share as {FileName}", filename);
}
else
{
Logger.Error("Image NOT saved before native share as to path {FileName}. {Error}", filename, err.Description);
return;
}
}
// this are the items that needs to be shared
// Instagram ignores the caption, that is known
var activityItems = new List<NSObject>
{
new NSString(shareCaption),
new NSUrl(new Uri(filename).AbsoluteUri)
};
// Here i add the custom UIActivity for Instagram
UIActivity[] applicationActivities =
{
new InstagramActivity(image, sourceRect, sourceView),
}
var activityViewController = new UIActivityViewController(activityItems.ToArray(), applicationActivities);
activityViewController.SetValueForKey(new NSString(emailSubject), new NSString("subject"));
activityViewController.CompletionWithItemsHandler = (activityType, completed, returnedItems, error) =>
{
UserSharedTo(activityType, completed);
};
// Hide some of the less used activity types so that Instagram shows up in the list. Otherwise it's pushed off the activity view
// and the user has to scroll to see it.
activityViewController.ExcludedActivityTypes = new[] { UIActivityType.AssignToContact, UIActivityType.CopyToPasteboard, UIActivityType.Print };
if(UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone)
{
PresentViewController(activityViewController, true, null);
}
else
{
activityViewController.ModalPresentationStyle = UIModalPresentationStyle.Popover;
PresentViewController(activityViewController, true, null);
// Get the popover presentation controller and configure it.
UIPopoverPresentationController presentationController = activityViewController.PopoverPresentationController;
presentationController.PermittedArrowDirections = UIPopoverArrowDirection.Down;
presentationController.SourceRect = sourceRect;
presentationController.SourceView = sourceView;
}
}
// when opening custom activity use ".igo" to only show instagram
public class InstagramActivity : UIActivity
{
public InstagramActivity(UIImage imageToShare, CGRect frame, UIView view, string shareCaption = "")
{
_ImageToShare = imageToShare;
_Frame = frame;
_View = view;
}
public override UIImage Image { get { return UIImage.FromBundle("Instagram"); } }
public override string Title { get { return "Instagram"; } }
public override NSString Type { get { return new NSString("PostToInstagram"); } }
public string Caption { get; set; }
public override bool CanPerform(NSObject[] activityItems)
{
return UIApplication.SharedApplication.CanOpenUrl(NSUrl.FromString("instagram://app"));
}
public override void Prepare(NSObject[] activityItems)
{
}
public override void Perform()
{
string filename = Path.Combine(FileSystemUtils.GetTemporaryDataPath(), "Image.igo");
NSError err = null;
using(var imgData = _ImageToShare.AsJPEG(JpgImageQuality))
{
if(imgData.Save(filename, false, out err))
{
Logger.Information("Instagram image saved as {FileName}", filename);
}
else
{
Logger.Error("Instagram image NOT saved as to path {FileName}. {Error}", filename, err.Description);
Finished(false);
return;
}
}
var url = NSUrl.FromFilename(filename);
_DocumentController = UIDocumentInteractionController.FromUrl(url);
_DocumentController.DidEndSendingToApplication += (o, e) => Finished(true);
_DocumentController.Uti = "com.instagram.exclusivegram";
if(!string.IsNullOrEmpty(ShareCaption))
{
_DocumentController.Annotation = NSDictionary.FromObjectAndKey(new NSString(ShareCaption), new NSString("InstagramCaption"));
}
_DocumentController.PresentOpenInMenu(_Frame, _View, true);
}
UIImage _ImageToShare;
CGRect _Frame;
UIView _View;
UIDocumentInteractionController _DocumentController;
}
I am using this code for sharing in Xamarin IOS:
public void Share(string title, string content)
{
if (UIApplication.SharedApplication.KeyWindow == null || UIApplication.SharedApplication.KeyWindow.RootViewController == null)
return;
if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(content))
return;
var rootController = UIApplication.SharedApplication.KeyWindow.RootViewController;
var imageToShare = UIImage.FromBundle("icon_120.png");
var itemsToShare = new NSObject[] { new NSString(content), imageToShare };
var shareStatusController = new UIActivityViewController(itemsToShare, null)
{
Title = title
};
//shareStatusController.NavigationController.NavigationBar.TintColor = UIColor.Black;
//rootController.NavigationController.NavigationBar.TintColor = UIColor.Black;
//shareStatusController.NavigationBar.TintColor = UIColor.FromRGB(0, 122, 255);
rootController.PresentViewController(shareStatusController, true, null);
Mvx.Resolve<IAnalyticsService>().LogEvent("Share button clicked.");
}
When i choose mail and i am redirected here http://take.ms/3KE4F. But color of cancel and send buttons is white (in NavigationBar). How can i change color of text of this button?
I found article
Cannot set text color of Send and Cancel buttons in the mail composer when presented from the UIActivityViewController in iOS7. But dont know howto apply this using Xamarin.
Thanks for any help.
Try this out:
public void Share(string title, string content)
{
if (UIApplication.SharedApplication.KeyWindow == null || UIApplication.SharedApplication.KeyWindow.RootViewController == null)
return;
if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(content))
return;
//Share Barbutton tint
UIBarButtonItem.AppearanceWhenContainedIn (new [] {typeof(UINavigationBar)}).TintColor = UIColor.Cyan;
var rootController = UIApplication.SharedApplication.KeyWindow.RootViewController;
var imageToShare = UIImage.FromBundle("icon_120.png");
var itemsToShare = new NSObject[] { new NSString(content), imageToShare };
var shareStatusController = new UIActivityViewController(itemsToShare, null)
{
Title = title
};
shareStatusController.CompletionHandler += (NSString arg1, bool arg2) => {
// Set it back to old theme theme
UIBarButtonItem.AppearanceWhenContainedIn (new [] {typeof(UINavigationBar)}).TintColor = UIColor.White;
};
rootController.PresentViewController(shareStatusController, true, null);
Mvx.Resolve<IAnalyticsService>().LogEvent("Share button clicked.");
}
You basically set the the button tint before you present the controller then set it back in completion handler.
The IMapViewDelegate apparently isn't a complete C# implementation of MapViewDelegate from objC. That inhibits the access to markerInfoContents delegate method.
I'd like to do something like this allowing me to custom the contentView layout and the tap action
got from: http://www.raywenderlich.com/81103/introduction-google-maps-ios-sdk-swift
I think i can explan its from scratch to add a Custom MarkerInfo Window on the Tap of a Marker. Iam using Xamarin.Google.iOS.Maps package from Official Nuget Library for adding Google Map on my Xamarin MVVM Cross Touch Project.
private void SetupMap()
{
if (_mapView != null)
_mapView.RemoveFromSuperview ();
//Init Map wiht Camera
var camera = new CameraPosition(new CLLocationCoordinate2D(36.069082, -94.155976), 15, 30, 0);
_mapView = MapView.FromCamera(RectangleF.Empty, camera);
_mapView.MyLocationEnabled = true;
//Add button to zoom to location
_mapView.Settings.MyLocationButton = true;
_mapView.MyLocationEnabled = true;
_mapView.Settings.SetAllGesturesEnabled(true);
var xamMarker = new Marker () {
Title = "Sample",
Snippet = "Sample Location",
Position = new CLLocationCoordinate2D (36.069082, -94.155976),
Map = _mapView
};
var xamMarker1 = new Marker () {
Title = "Sample1",
Snippet = "Sample Location2",
Position = new CLLocationCoordinate2D (35.069082, -94.155976),
Map = _mapView
};
_mapView.TappedMarker = (map, marker) => {
Console.WriteLine("Marker tapped:"+ map +"::"+marker);
_mapView.MarkerInfoWindow = new GMSInfoFor(markerInfoWindow);
return false;
};
_mapView.Frame = this.contentViewOutlet.Bounds;
this.contentViewOutlet.AddSubview (_mapView);
_mapView.InfoTapped += (object sender, GMSMarkerEventEventArgs e) => {
Console.WriteLine ("Marker Info tapped:"+e+"::"+sender);
UIAlertView alert = new UIAlertView () {
Title = "Alert", Message = sampleLongandLat
};
alert.AddButton("OK");
alert.Show ();
};
}
you can call this SetupMap() method from where ever you want. for example in ViewDidLoad or from any where you have to add the google map.
On click or Tap of the marker we are creating a custom marker window
_mapView.TappedMarker = (map, marker) => {
Console.WriteLine("Marker tapped:"+ map +"::"+marker);
_mapView.MarkerInfoWindow = new GMSInfoFor(markerInfoWindow);
return false;
};
the above code is included in the SetupMap method.
mapView.MarkerInfoWindow = new GMSInfoFor(markerInfoWindow); these above line of code will allow us to load a custom Marker Window instead of the default one
UIView markerInfoWindow(UIView view, Marker marker)
{
// use this method to return the custom view u have already created to load as a subview in Google Map as Custom Marker Info Windo
UIView v;
v = MarkerInfoView.Create(marker);
sampleLongandLat = MarkerInfoView.markerInfoString;
sampleLongandLat = MarkerInfoView.locationIDString;
return v;
}
for adding an custom UIView you can follow the example provided in the xamarin web site loading an xib or UIView in another ViewController as a sub view
_mapView.InfoTapped += (object sender, GMSMarkerEventEventArgs e) => {
Console.WriteLine ("Marker Info tapped:"+e+"::"+sender);
UIAlertView alert = new UIAlertView () {
Title = "Alert", Message = sampleLongandLat
};
alert.AddButton("OK");
alert.Show ();
};
the above code snippet you can use for detecting tap on the Marker Info Window