Share button on Xamarin.forms.ios - ios

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.

Related

Detecting ARKit compatible device from user agent

We would like to enable a feature that allows a model to be viewed using a deep link to our ARKit app from a web page.
Has anyone discovered a way to discover if a device is ARKit compatible using the user agent string or any other browser-based mechanism?
Thanks!
Apple seems to use the following code to show/hide the "Visit this page on iOS 12 to try AR Quick Look" on https://developer.apple.com/arkit/gallery/
(function () {
var isRelAR = false;
var a = document.createElement('a');
if (a.relList.supports('ar')) {
isRelAR = true;
}
document.documentElement.classList.add(isRelAR ? 'relar' : 'no-relar');
})();
The interesting part of course being
var isRelAR = false;
var a = document.createElement('a');
if (a.relList.supports('ar')) {
isRelAR = true;
}
Make your actions accordingly based on the value of isRelAR.
Safari doesn’t expose any of the required hardware information for that.
If you already have a companion iOS app for your website, another option might be to still provide some non-AR experience for your content, so that the website has something to link to in all cases.
For example, AR furniture catalogs seem to be a thing now. But if the device isn’t ARKit capable, you could still provide a 3D model of each furniture piece linked from your website, letting the user spin it around and zoom in on it with touch gestures instead of placing it in AR.

iOS only, share image from gallery to my Ionic/Cordova/Phonegap application

I am trying to share image from gallery and want to get it in my ionic application. I have tried a lot but still not understanding this.
I have tried following plugins:
https://github.com/protonet/cordova-plugin-share-extension-helper
https://github.com/markmarijnissen/cordova-plugin-share
How to share content/data through other apps in an iOS app like we do in an Android app with Intent.ACTION_SEND?
http://www.technetexperts.com/mobile/share-extension-in-ios-application-overview-with-example/
https://github.com/LokeshPatel/iOS-Phonegap-app-share-extension
After some detailed analysis, this is what I could conclude:
In Android, you could just get your application added in the share list using cordova-plugin-intent as described in this SO Post. You can also achieve this by adding intent filter in the activity as described here
In iOS, this is bit tricky as there are no straight forward plugins or readymade solution available to achieve this. But the best possible link i could get related to adding app in iOS share menu is getting listed in share menu The link includes apple documentation to do this and also some tweaking in Info.plist to achieve this.
You can use this plugin https://github.com/wymsee/cordova-imagePicker
The usage has been described there. It gives you the path of the image.
You can use that path or read the imagefile to get base64 equivalent of it. e.g.
window.imagePicker.getPictures(
function(results) {
for (var i = 0; i < results.length; i++) {
createImage(results[i])
}
}, function (error) {
console.log('Error: ' + error);
})
createImage(fileURL){
var img = new Image();
img.crossOrigin = 'Anonymous';
img.src = fileURL;
img.onload = function(){
// processing
}}

ZXing barcode scanner in Xamarin Forms on iOS doesn't read barcodes

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.

Unity Facebook SDK - iOS 8 Login Issues

I've had Facebook integrated in my Unity app, and I've been using it on my iPhone 5 with iOS 7 with no problem. But the problem comes when I try it on my friend's iPhone 6 running iOS 8. When I make a call to FB.Login() it switches to the Facebook app, as it normally should, but when it comes back to my app, Facebook opens the Webview for the Facebook login page with the error "You must log in to continue."
The app registers that Facebook.IsLoggedIn is true, and the app continues as if it's logged in, but the Webview is still there and I have to close it to get back to my app.
The only real clue I have about what could be wrong is that the LoginCallback is being called twice in iOS 8 but not in iOS 7.
Any relevant code is below, but it seems like the issue is coming from within the Facebook SDK itself.
public static readonly string FB_SCOPE = "email,public_profile,user_friends";
FB.Login(FB_SCOPE,FBLoginResult);
void FBLoginResult(FBResult result) {
Debug.Log (result.Text);
}
Anyone have any idea, or experience anything similar?
I had the exact same problem. Turns out the FB.Login code was fired twice.
I suggest you write a log near the FB.Login and make sure you don't see it twice.
It seems that this is due to a bug in Unity3D specific to iOS 8. See here for details : http://fogbugz.unity3d.com/default.asp?692236_po26b9sb1uqlag7p
Here is a workaround to fix the problem in NGUI. Go to UICamera.cs and add the following line of code in the function public void ProcessTouches ()
MouseOrTouch touch = null;
if (input.phase == TouchPhase.Ended && !mTouches.TryGetValue(currentTouchID, out touch))
return;
just after this :
for (int i = 0; i < Input.touchCount; ++i)
{
Touch input = Input.GetTouch(i);
currentTouchID = allowMultiTouch ? input.fingerId : 1;

Play default iOS system sound with Monotouch

I want to play the keyboard 'click' sound when pressing buttons in my app.
How do I access this sound clip with Monotouch? I don't want to pass my own sound using AudioToolbox SystemSound.FromFile(). So far all my searches have led to this solution or Objective-C code using 'AudioServicesCreateSystemSoundID' which I'm having trouble translating to C#.
With iOS 7.0 and higher, Stephane Delcroix answer seems not to work anymore...
But you can easily find the path to all the sounds in this nice project:
https://github.com/TUNER88/iOSSystemSoundsLibrary
Here is the code I used und iOS 7 (take care, it might not work with the simulator!)
private const string NotificationSoundPath = #"/System/Library/Audio/UISounds/New/Fanfare.caf";
public static void TriggerSoundAndViber()
{
SystemSound notificationSound = SystemSound.FromFile(NotificationSoundPath);
notificationSound.AddSystemSoundCompletion(SystemSound.Vibrate.PlaySystemSound);
notificationSound.PlaySystemSound();
}
Also the using() construct in the answer above caused trouble in my case... it seems like it released the sound too early, I only can hear it (and even then not complete with viber) with a breakpoint on PlaySystemSound().
Well, that's not a 1:1 port from the code in Playing system sound without importing your own, but this should do the work:
var path = NSBundle.FromIdentifier ("com.Apple.UIKit").PathForResource ("Tock", "aiff");
using (var systemSound = new SystemSound (NSUrl.FromFilename (path))) {
systemSound.PlaySystemSound ();
}
SystemSound is defined in MonoTouch.AudioToolbox. Make sure to also look at MonoTouch Play System Sound and MonoTouch: Playing sound

Resources