I am writing my first ever mobile app for IOS using Xamarin and i need to use the camera to scan a product barcode similar to the function of many shopping apps. Would any of you lovely people know how i go about this or if there are any plug-ins for this?
Thanks
Steve
For the most part, I have found ZXing Mobile to be the best option as far as reading barcodes is concerned.
The syntax is very .NET friendly:
buttonScan.Click += (sender, e) => {
var scanner = new ZXing.Mobile.MobileBarcodeScanner();
var result = await scanner.Scan();
if (result != null)
Console.WriteLine("Scanned Barcode: " + result.Text);
};
Source and more info: https://components.xamarin.com/view/zxing.net.mobile
Related
I'm working on a Xamarin Forms PCL project targeting Android and iOS that needs some basic barcode scanning functionality.
I got things up and running with the forms version of the ZXing.Net.Mobile package following this tutorial and referencing this guide and it works great on Android. However, on iOS the camera comes up but the OnScanResult event is never fired.
I've tested it on several iOS devices running several different versions (anywhere from 8.0 - 10.3) and fiddled with everything I can think of, referencing their sample projects as well. ZXing.Net.Mobile and ZXing.Net.Mobile.Forms nuget packages were installed in all projects.
Here's my scanner code, triggered from a button press on my main page:
var scanPage = new ZXingScannerPage();
scanPage.OnScanResult += (result) =>
{
scanPage.IsScanning = false;
Device.BeginInvokeOnMainThread(async () =>
{
await Navigation.PopAsync();
await DisplayAlert("Scanned Barcode", result.Text, "OK");
});
};
await Navigation.PushAsync(scanPage);
and AppDelegate.cs:
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
global::ZXing.Net.Mobile.Forms.iOS.Platform.Init();
LoadApplication(new App());
return base.FinishedLaunching(app, options);
}
After two days of fighting with this, I feel like I'm at my wit's end. Has anyone else encountered similar problems? Thanks for any guidance!
Edit 1
Here's the device log output (Message column only) when clicking the button to trigger the above code. No log items are added while the camera is open and pointed at various barcodes. I don't see anything suspicious here, but maybe someone else does?
PERF: Alloc AVCaptureVideoPreviewLayer took 14.14 ms.
AppleH4CamIn::power_on_hardware
AppleH4CamIn::ISP_SelectBestMIPIFrequencyIndex_gated - channel: 0, index: 0
StartScanning
AppleH4CamIn::setPowerStateGated: 1
ZXingScannerView.Setup() took 0.167 ms.
ASL Sender Statistics
AppleH4CamIn::ISP_FlushInactiveDARTMappings: 0x00000000
AppleH4CamIn::ISP_SelectBestMIPIFrequencyIndex_gated - channel: 0, index: 0
Edit 2
I ran the sample Xamarin Forms PCL from the github repo and am having the same problems on iOS with the camera opening fine, but no barcode ever read. Therefore I'm thinking the problem must be with my Visual Studio and/or Xamarin setup. I'm running Visual Studio 2015 Community on the stable Xamarin channel.
add this on ios
protected override void OnAppearing()
{
base.OnAppearing();
qrcode.IsScanning = true;
}`enter code here`
protected override void OnDisappearing()
{
qrcode.IsScanning = false;
base.OnDisappearing();
}
Try using this:
scanPage.IsAnalyzing = true;
IsAnalyzing is different from IsScanning.
I faced the same the issue like you. But after using IsAnalyzing = true; It is fixed.
I finally got it working with this project as a starting point. It's just a basic barcode scanning implementation using ZXing, but for whatever reason I could finally read barcodes on iOS.
It's probably a version-related problem, but I couldn't narrow it down.
Edit
I posted this same question in the Xamarin Forums: https://forums.xamarin.com/discussion/comment/272209#Comment_272209
It seems the answer was downgrading to ZXing version 2.1.47. I haven't done any work with the library for a few months so I haven't tested new versions.
I've developed an app using Cordova and the Web Audio API, that allows the user to plug in headphones, press the phone against their heart, and hear their own heartbeat.
It does this by using audio filter nodes.
//Setup userMedia
context = new (window.AudioContext||window.webkitAudioContext);
navigator.getUserMedia = (navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia);
navigator.getUserMedia(
{audio:true},
userMediaSuccess,
function(e) {
alert("error2 " + e.message);
});
function userMediaSuccess(stream)
{
//set microphone as input
input = context.createMediaStreamSource(stream);
//amplify the incoming sounds
volume = context.createGain();
volume.gain.value = 10;
//filter out sounds below 25Hz
lowPass = context.createBiquadFilter();
lowPass.type = 'lowpass';
lowPass.frequency.value = 25;
//filter out sounds above 425Hz
highPass = context.createBiquadFilter();
highPass.type = 'highpass';
highPass.frequency.value = 425;
//apply the filters and amplification to microphone input
input.connect(lowPass);
input.connect(highPass);
input.connect(volume);
//send the result of these filters to the phones speakers
highPass.connect(context.destination);
lowPass.connect(context.destination);
volume.connect(context.destination);
}
It runs fine when I deploy to Android, but it seems most of these features aren't available on iOS mobile browsers.
I managed to make getUserMedia function using the iosRTC plugin, but createMediaStreamSource is still "not a function."
So, I'm looking for an alternative to the Web Audio API that can filter out frequencies, or if there are any plugins I could use, that would be perfect.
There's no way to do this on ios web. You'd need a native app, since Apple doesn't support audio input in safari.
Did you try to use
document.addEventListener('deviceready', function () {
// Just for iOS devices.
if (window.device.platform === 'iOS') {
cordova.plugins.iosrtc.registerGlobals();
}
});
You asked this question quite a while ago, but sadly createMediaStreamSource is still not supported in Safari Mobile (will it ever be?).
As previously said, a plugin is the only way to achieve this, and there is actually a Cordova/Phonegap plugin that does exactly that. cordova-plugin-audioinput gives you access to the sound from the microphone using either the Web Audio API or by callbacks that delivers raw audio data chunks, and it supports iOS as well as Android.
Since I don't want to post the same answer twice, I'll instead point you to the following answer here on stackoverflow, where you'll also find a code example: https://stackoverflow.com/a/38464815/6609803
I'm the creator of the plugin and any feedback is appreciated.
Good news, full support for ios safari
https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createMediaStreamSource
I'm a beginner on Xamarin ant try to create simple app with Xamarin.forms.
Now i need to add share button (square + arrow like on Safari on iPhone) to my App. As I know that Android and IOS are differant so that I use DependencyService.
It works good on Android using Intent but can't do it on IOS.
can you help me please.
thanks all,
this is my code
PCL
var x = DependencyService.Get<IShareable>();
x.ShareText("any text to share");
Android
public void ShareText(string textToShear)
{
var myIntent = new Intent(Android.Content.Intent.ActionSend);
myIntent.SetType("text/plain");
myIntent.PutExtra("sms_body", textToShear);
Forms.Context.StartActivity(Intent.CreateChooser(myIntent,"Choose an App"));
}
IOS
public void ShareText(string textToShear)
{
//what i should do
}
You want to use UIActivityViewController.
It will look something like this:
public void ShareText(string textToShare)
{
var activityController = new UIActivityViewController(new NSObject[] { UIActivity.FromObject(textToShare) }, null);
UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(activityController, true, null);
}
I am in the exact same position.
What I have found out so far:
iOS apps typically use something called Sharekit, but I haven't found anyone using that with Xamarin.Forms
Since iOS 6 there is an easier way to share with objective c, but I'm not sure how we could convert that to C# / Xamarin.
There is a social plugin for Xamarin called Xamarin.Social that allows users to log in and post things from your app. Of course this isn't what we want to do... ideally we would like the same functionality that is in Android.
I'm sorry I couldn't be of more help. If I find an answer that works I will update you.
I'm trying to implement speech recognition on Chrome on the iPad without any luck. Just to cut to the chase and remove any dependencies on my implementation of the webkitSpeechRecognition api, Glenn Shire's excellent sample code does not run on Chrome v27 on an iPad 1 running iOS 5.1.1 or Chrome v31 on an iPad3 running iOS 7.0.4, at least as far as I can tell. It fails at this line:
if (!('webkitSpeechRecognition' in window)) {
r.onState('upgrade');
return;
}
I can't figure out a workaround, and I've not seen any online postings that say anything about speech recognition not working in the iOS version of Chrome. Anyone else run into this?
Chrome on iOS doesn't support Speech Recognition at the moment.
Google have to use iOS UIWebView that mean there is no special web interpretation feature that are not supported on Safari.
You may have a look to this link.
In case you want to recognize few simple commands you can look on Pocketsphinx.js
The code to recognize speech is simple:
var id = 0;
recognizer.postMessage({command: 'initialize', callbackId: id});
var keyphrase = "HELLO WORLD";
recognizer.postMessage({command: 'addKeyword', data: keyphrase, callbackId: id});
recognizer.postMessage({command: 'start', data: id});
recognizer.postMessage({command: 'process', data: array});
recognizer.postMessage({command: 'stop'});
recognizer.onmessage = function(e) {
if (e.data.hasOwnProperty('hyp')) {
alert(e.data.hyp);
}
};
For more details see also the full example here
Is it possible to create an application with Mono for Android and control Arduino without using Eclipse but using Visual Studio and C#?
I checked some examples but everyone uses Java and Eclipse.
Simply put, the answer is yes, it is possible. The real question is: How? I'm going to assume you've already written you first Android app with Mono.
Next, you need to decide how you will connect your Android device to the Arduino. Bluetooth? Wi-Fi? Web?
Next, it's simply a matter of using the appropriate Android API. Check out the Xamarin documentation for Android.
Update
Much more than what I present below is available with the ported MonoDroid sample applications. Specifically, you would be interested in the BluetoothChat example.
Make sure you also take a look at adding permissions to the manifest file, and of course, the Android Developer Guide for Bluetooth.
That said, here's a tiny something to get you started, based on Android Quick Look: BluetoothAdapter:
txtStatus.Text = "Getting Bluetooth adapter...";
BluetoothAdapter bluetooth = BluetoothAdapter.DefaultAdapter;
if( bluetooth == null )
{
txtStatus.Text = "No Bluetooth adapter found.";
return;
}
txtStatus.Text = "Checking Bluetooth status...";
if (!bluetooth.IsEnabled )
{
Toast.MakeText(this, "Bluetooth not enabled. Enabling...",
ToastLength.Short).Show();
bluetooth.Enable();
}
if (bluetooth.State == State.On)
{
txtStatus.Text =
"State: " + bluetooth.State + System.Environment.NewLine +
"Address: " + bluetooth.Address + System.Environment.NewLine +
"Name: " + bluetooth.Name + System.Environment.NewLine;
}
else
{
txtStatus.Text = "State: " + bluetooth.State;
}