I am writing a mobile app in xamarin forms and I have half the screen continuously scanning barcodes using ZXingScannerView. This works great in android however in ios it will not pick up any barcodes using ZXingScannerView. However ios does pick up barcodes using the full page ZXingScannerPage. In my example code below the method Scanner_OnScanResult is never getting hit. How can I get this to work in ios am i missing something?
ZXingScannerView scanner = new ZXingScannerView
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
AutomationId = "zxingScannerView",
IsScanning = true,
Options = new ZXing.Mobile.MobileBarcodeScanningOptions
{
UseFrontCameraIfAvailable = false,//update later to come from settings
PossibleFormats = new List<ZXing.BarcodeFormat>(),
TryHarder = true
}
};
ZXingDefaultOverlay overlay = new ZXingDefaultOverlay();
scanner.Options.PossibleFormats.Add(ZXing.BarcodeFormat.QR_CODE);.
scanner.OnScanResult += Scanner_OnScanResult;
private void Scanner_OnScanResult(ZXing.Result result)
{
DisplayAlert("Exit", "TEST", "Yes", "No");
}
I eventually got this working however i'm not sure if its a bug or just inconsistent design but in iOS IsAnalyzing must be set to true manually when working in a view
Related
I have Xamarin Native (iOS/Droid) app. In older iOS versions, navigating back to previous viewControllers can be done by swiping right with one animation that drags the current view for the screen. When updating to the newest iOS 13, this animation doesn't appear anymore. The ViewWillDissapper doesn't get called either.
What am i missing?
I already tried this changes:
this.ModalInPresentation = true;
this.ModalPresentationStyle = UIModalPresentationStyle.FullScreen;
NavigationController.InteractivePopGestureRecognizer.Enabled = true;
NavigationController.InteractivePopGestureRecognizer.Delegate = new MyGestureDelegate();
In iOS 13 , you can set that in the previous ViewController as follow :
UIViewControllerSecond viewControllerSecond = new UIViewControllerSecond();
viewControllerSecond.ModalPresentationStyle = UIModalPresentationStyle.FullScreen;
viewControllerSecond.ModalTransitionStyle = UIModalTransitionStyle.FlipHorizontal;
PresentViewController(viewControllerSecond, true, null);
Then in second ViewController just DismissModalViewController(true); when back .
UISwipeGestureRecognizer swipeGesture = new UISwipeGestureRecognizer();
swipeGesture.Direction = UISwipeGestureRecognizerDirection.Right;
swipeGesture.AddTarget(() => { Console.WriteLine("-swipe-to-right-"); DismissViewController(true, null); });
View.AddGestureRecognizer(swipeGesture);
Have a look at this effect , whether it is needs .
The app is using Xamarin Native with Mvvm Cross. Turns out that the mvvm cross package in version 4.4 don't support iOS 13, and updating it to 5.7 solved my problem
I am trying to implement a barcode scanning app using Xamarin and ZXing. Unfortunately scanning is not working well with front camera on iPhone and iPad. Any suggestions or help appreciated
Your InitializeScanner method can do scanner initialization as below and invokes start scanning, in my case I wanted to support barcode and QR code both. You can remove scanning option QRCode if you do not want to support it.
The callback mentioned while initialization is getting called back when scanner recognizes the code and returns unique string.
The scanner option has property UseFrontCameraIfAvailable
var mobileBarcodeScanningOptions= new ZXing.Mobile.MobileBarcodeScanningOptions();
mobileBarcodeScanningOptions.UseFrontCameraIfAvailable = true;
mobileBarcodeScanningOptions.PossibleFormats = new List<ZXing.BarcodeFormat>() {
ZXing.BarcodeFormat.CODE_128,
ZXing.BarcodeFormat.CODE_93,
ZXing.BarcodeFormat.CODE_39,
ZXing.BarcodeFormat.PDF_417,
ZXing.BarcodeFormat.QR_CODE
};
mobileBarcodeScanningOptions.AutoRotate = false;
mobileBarcodeScanningOptions.TryHarder = true;
mobileBarcodeScanningOptions.TryInverted = false;
var scanview = new ZXingScannerView(new CGRect(0, 0, View.Frame.Width, View.Frame.Height)) { }
scanview.AutoFocus();
//code to add your scanview in your main view
scanview.StartScanning(MyScanResultHandler, mobileBarcodeScanningOptions);
//After scanning code, scanner callbacks below method
private void MyScanResultHandler(Result obj)
{
if (obj != null)
{
//obj.Text gives you value of code in string which you can use further in your application
}
}
I am currently testing my xamarin iOS app on TestFlight with an iOS device. The app is running fine but the images in my UIButtons arent showing up at all.
Heres my button code:
_uiAttributes.myScheduleImage = UIImage.FromFile("images/myschedule.PNG");
_uiAttributes.myCareersImage = UIImage.FromFile("images/mycareer.PNG");
_uiAttributes.mySocialImage = UIImage.FromFile("images/mysocial.PNG");
_uiAttributes.FeedbackImage = UIImage.FromFile("images/feedback.PNG");
_uiAttributes.myDetailsImage = UIImage.FromFile("images/mydetails.PNG");
buttonList = new List<UIButton>
{
_uiControls.btn_MySchedule,
_uiControls.btn_MyCareer,
_uiControls.btn_MySocial,
_uiControls.btn_Feedback,
_uiControls.btn_MyDetails
};
buttonImageList = new List<UIImage>
{
_uiAttributes.myScheduleImage,
_uiAttributes.myCareersImage,
_uiAttributes.mySocialImage,
_uiAttributes.feedbackImage,
_uiAttributes.myDetailsImage
};
I pass this code through to a Draw method.
public void DrawImageButton(List<UIButton> buttonList, List<CGRect> buttonDimensionsList, List<UIImage> buttonImageList, UIView container)
{
for(int i = 0; i < buttonList.Count; i++)
{
buttonList[i].Frame = buttonDimensionsList[i];
buttonList[i].SetImage(buttonImageList[i], UIControlState.Normal);
container.AutoresizingMask = UIViewAutoresizing.FlexibleMargins;
buttonList[i].AutoresizingMask = UIViewAutoresizing.FlexibleWidth;
container.AddSubview(buttonList[i]);
}
}
The buttons are showing up when i run it on a simulator but not my actual device.
I will attach an screenshot of my images below:
Resources/images
I have checked a number of related answers but theyre all in Xcode. I am currently using Visual Studio 2015 to develop my application.
If anyone can help or point me in the right direction that would be great.
So I have managed to fix this issue. The problem was that i never changed the Copy to Output Directory to "Copy Always" in the properties panel for each image. Also I had to state the path of the image being loaded.
_uiAttributes.myScheduleImage = UIImage.FromFile("images/myschedule.PNG");
Thanks for all the help!
I have the following code that sets up a WebView inside my Xamarin.Forms Cross Platform application:
ReportsListWebView = new WebView()
{
VerticalOptions = LayoutOptions.FillAndExpand,
HorizontalOptions = LayoutOptions.FillAndExpand,
BackgroundColor = Xamarin.Forms.Color.Transparent
};
URLReportsListWebView = new UrlWebViewSource
{
Url = "http://192.168.0.96/MyWebsite/App/MiniMyWebsite?ActionType=Listing&Params=Reports"
};
ReportsListWebView.Source = URLReportsListWebView;
grid.Children.Add(ReportsListWebView, 0, 4, 0, 1);
The situation is that there is listing within the website that I am referencing in the WebView. When the user selects an item in the listing on the webpage it has javascript that changes the url of the website (appends #SelectedItem=1 to the url). I just want to be able to recognize this change from within the application.
I've checked the URLReportsListWebView.Url but it doesn't seem to update with the latest changes. Any ideas on how to achieve this?
Thanks
This ended up being a limitation on the xamarin forms webview control. The work around was to create a custom renderer which the Xamarin support provided me a great same showing how to accomplish this at github.com/jgold6/XFormsWebViewCustomRenderer/tree/master
When I've done a few tests against http://www.yahoo.com it appears to be updating the WebView.Source property ok, even with query string attribues.
Are you just updating the location of the current webpage rather than navigating to a new page?
Maybe this could be the reason why its not working for you?
If so, after the change, you will then be able to monitor the .Source property for the newly navigated webpage as there is no event handler or anything to hook into to get notified when a page has been navigated to / fully loaded.
Update 1:-
Try the following that is working for me.
It should produce updates similar to the following:-
http://www.yahoo.com
https://fr.yahoo.com/?p=us
https://fr.news.yahoo.com/syrie-jihadistes-exécutent-160-soldats-43-casques-bleus-050134941.html
http://www.tv3g.bouquettv.mobi/wap/landing/landing2.asp?c=LFYAH_TVGREEN_AAAMMM&IDLanding=16972&tag=0&Alea=7.906741E-02&Al=MM201408290946299694
Code:-
StackLayout objStackLayout = new StackLayout()
{
};
//
WebView objWebView1 = new WebView();
objWebView1.HeightRequest = 300;
objStackLayout.Children.Add(objWebView1);
//
UrlWebViewSource objUrlToNavigateTo = new UrlWebViewSource()
{
Url = "http://www.yahoo.com"
};
objWebView1.Source = objUrlToNavigateTo;
//
//
Button cmdButton1 = new Button();
cmdButton1.Text = "Show Me Current Url";
objStackLayout.Children.Add(cmdButton1);
//
cmdButton1.Clicked += ((o2, e2) =>
{
System.Diagnostics.Debug.WriteLine((objWebView1.Source as UrlWebViewSource).Url);
});
//
//
this.Content = objStackLayout;
If you don't yet have a custom renderer, you'll need to refer to Xamarin documentation to learn how to custom render Xamarin.Forms WebView.
If you already have the custom renderer, inside the CustomRenderer object, you should access the NativeWebview object and assign HandleShouldStartLoad to its ShouldStartLoad event handler. My mistake was that I assigned HandleShouldStartLoad to the event handler of the renderer itself, which won't work.
I'm writing Windows Phone 8 app that needs to get location of device (do not track changes, just get location). I added next code to the method OnNavigatedTo() of my start page but after launching app, the progress indicator does not hide even after 10 seconds timeout. But if I navigate to another page and then go back, everything works fine. This happens on the emulator, I don't have a real device. What am I doing wrong?
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
if(_geoPosition == null)
{
try
{
var geolocator = new Geolocator();
geolocator.DesiredAccuracyInMeters = 50;
_progressIndicator = new ProgressIndicator
{
IsIndeterminate = true,
Text = "Getting current location, please wait...",
IsVisible = true
};
SystemTray.SetIsVisible(this, true);
SystemTray.SetProgressIndicator(this, _progressIndicator);
_geoPosition = await geolocator.GetGeopositionAsync(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(10));
_progressIndicator.IsVisible = false;
SystemTray.SetIsVisible(this, false);
}
catch (UnauthorizedAccessException)
{
MessageBox.Show("Location is disabled in phone settings");
}
}
}
Thanks!
UPD: just tried to add this code to empty project and it works fine. Tried to comment out some parts of OnNavigatedTo that I did not include to the snippet and found out that the reason somewhere in initialization of data source for this page. I'm sorry for false alarm.
Your code works fine for me, try the classic restart VS and the projecy!
The code should work, tested it with an emulator and a device (nokia 820).
Best of luck