App won't start with Xamarin iOS Facebook SDK - xamarin

I have no idea what's going wrong. I just want to integrate the Facebook iOS SDK from Xamarin and call the 'ActivateApp' Event, so that I can see how many users opened the app from the Facebook-App with an ad from me.
I created a blank Xamarin.Forms app, added the component from the component store and modified my AppDelegate class:
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
Settings.AppID = "<myFacebookId>";
global::Xamarin.Forms.Forms.Init();
LoadApplication(new App());
return base.FinishedLaunching(app, options);
}
I am aware that I need to update the Info.plist file also and do some more stuff. But the special here is, with above steps the app won't start on my device (Configuration: Debug | iPhone, Linker disabled, sdk Version 9.2, deployment target 7.1) but on my smulator it works fine.
On the device, the splashscreen just shows for half a second, then it crashs without any Feedback.
My brain explodes next time. Any help is appreciated. Thanks

Thanks to the Xamarin-support, I have a solution for my problem.
Answer from the Support:
It looks like the issue you are hitting is related to App Transport
Security, so you’ll need to whitelist a couple things by editing your
plist to fix the crash on device. You can read more about how to do
this in the Facebook developer guide, “Preparing Your Apps for iOS
9”:
Basically, what you’ll do is this:
Double-click info.plist and go to Source tab
Add Custom Property “LSApplicationQueriesSchemes”, type “Array”
Add Strings with the following values: fbapi, fb-messenger-api, fbauth2, fbshareextension
It’s a little bit akward… As I wrote you in my question, I am aware that there are more things to do (like editing the plist-file). But unfortunately, I obviously put the wrong values in my plist-file.

Related

Xamarin iOS Library can't get location

I have a vendor provided .framework file that I created an iOS binding project for using Objective Sharpie. I can call into the library, get callbacks, pull data, mostly everything works except the library being able to access the current location. The public headers for that project are here StripeTerminal
In my C# code, I used the Xamarin.Essentials to pull the current location.
var location = await Geolocation.GetLastKnownLocationAsync();
This returns with my location both in the simulator and on a real iPhone. I can see the access is granted to my app in the Privacy-> Location Services menu.
I have the below in my info.plist file, which I have tried targeting 9.0 SDK and 12.0 SDK.
<key>NSLocationWhenInUseUsageDescription</key>
<string>Location required for accepting payments.</string>
In an example XCode project provided by the vendor, that is able to pull the location by inspecting their verbose logs. In the Xamarin app, their logs get stuck on a requestLocation and never continue past it. I even tried setting the Link option to Don't Link and the result is the same.
What is wrong with my binding project that would prevent a native framework library from being able to access the location?
The issue was a mix of how Xamarin works and iOS. I created a CLLocationManager object in my C# code and setup a listener for location changes, except it never worked. So I tried the Xamarin.Essentials package to get the current location using GetLastKnownLocationAsync and that worked every time, so it wasn't a permission issue or a simulator issue. Digging into the Xamarin.Essentials code I found the below.
NSRunLoop.Main.InvokeOnMainThread(() => manager = new CLLocationManager());
Reading more documentation, I found that the CLLocationManager can only be successfully created from an active run loop. Wrapping calls into the Stripe Terminal iOS SDK in the NSRunLoop.Main.InvokeOnMainThread allowed things to work as they were creating a CLLocationManager expecting the call to be in an active run loop without checking first, or documenting that behavior. Stripe's internal code waited on a callback, which never happened, thus hanging the SDK in a weird state.

How to add admob ads to Xamarin IOS

I am trying to add Admob Ads to Xamarin.IOS but i am unable to figure out way to achieve this goal.I have already searched internet but couldnt find the solution
Google Admob is available in Xamarin.iOS .
1.install the package Xamarin.Firebase.iOS.AdMob from nuget.
2.Registring with AdMob
So, the first thing that you will need to do is actually register for AdMob. This is the same thing that I did in Android, but I created an iOS project. This will give you two important pieces of information, your “Application Code” and your “Ad Unit Id”. We will use these later, but simply go to: https://apps.admob.com, register for a new app, link to an app in Firebase, and you will be off running.
3.Add GoogleService-Info.plist
When you create the new app in Admob/Firebase there will be a Google Service config plist file that gets downloaded. Add this to the root of your iOS project and make sure that the Build Action is set to BundleResource. This is super important!
4.Update AppDelegate
MobileAds.Configure("Your Publishing App Id");
You can ask for more details about Admob . And here is a sample that you can refer.

Xamarin Forms App crashes after splash screen on iOS device

My Xamarin Forms App works fine in Android devices, but when trying do deploy on a real iOS device it crashes after the splash screen, I said real because I can run without any problem on the simulator.
I try to debug the App on a real iOS device, and I found that the crash happen when the App try to load the XAML file on:
private void InitializeComponent() {
global::Xamarin.Forms.Xaml.Extensions.LoadFromXaml(this, typeof(LoginPage));
Please take a look at the debug steps:
Regards,
Pedro
I found the problem. The [XamlCompilation(XamlCompilationOptions.Compile)] was missing on the code behind C# file, and because of that some methods used by click events of controls on the XAML were not available. But still can't find explanation for this not happening on the simulator!
In case it is a help to anyone, I had the same symptom for a different reason. I am using single page simple navigation in the app in question setting MainPage to the current page in the app. After few days of troubleshooting, happened to notice the checkbox in Application section of info.plist, "Supports Multiple Windows" was checked. Unchecking this restored my app to working condition. There were no diagnostic messages that seemed related, just a crash after splash in release mode, and a black screen in debug mode.

Xamarin.Forms application properties not saved between sessions with Android

In my cross-platform app I save application properties in the following way:
Application.Current.Properties["myValue"] = "Test";
await Application.Current.SavePropertiesAsync();
I then retrieve them later like this:
string myVal = Application.Current.Properties["myValue"];
This works perfectly when using the Android emulator. I can close the emulator down, and when I restart it again, my app data is preserved.
However, when I deploy this app to a physical Android device, data preservation works as expected until I close the app and open it again. At this point I retrieve an empty value. It's as though the data is only saved to memory (and not to file).
Furthermore, the iOS version of the exact same app works faultlessly. When I open the app up, all previous values have been saved and I can retrieve them.
What am I doing wrong on the Android version? Is there an Android setting, permission, or option which I need to enable to have the values saved between app sessions when actually deployed to a phone?
I had a similar problem where only the debug version saved Properties. I think we're still waiting for the bug fix, and this is the workaround on Xamarin Forms bugzilla.
In short: go to .Droid project settings -> Android Options -> Linker
and enter/add "System.Runtime.Serialization" to Skip linking assemblies.
Wow! After lots of research, I have getting solution for same issue in mine. Problem is that, when i store List or DataTable in Application.Current.Properties then all properties are removed after reopen app but if i store List or DataTable as serialize, it working fine.
In VS you need to enable the option:
Preserve application data/cache on device between deploys
You can find this at Tools > Options > Xamarin > Android Settings.
I don't know if this has stopped in the latest updates of Xamarin Forms, the data is available until the application is running similar to session but persistent storage does not work.
The best api I think available for this is Akavache https://github.com/akavache/Akavache.
You can read this blog https://codemilltech.com/akavache-is-aka-awesome/.
Update
There is a bug filed in bugzilla:
https://bugzilla.xamarin.com/show_bug.cgi?id=26444
I don't remember exactly which part of this solved the issue, but when I followed the instructions to prepare the Android application for release from start to finish, the issue went away. The problem occurred when debug builds were used on an Android device.
https://developer.xamarin.com/guides/android/deployment,_testing,_and_metrics/publishing_an_application/part_1_-_preparing_an_application_for_release/
The link details the suggested settings for the Android project when releasing to device. Following these instructions should solve the issue.

How can I make a Rate-Button in iOS7?

I want to add a rate-button to my application. How can I do this?
- (IBAction)rateGame {
[[UIApplication sharedApplication]
openURL:[NSURL URLWithString:#"itms-apps://itunes.apple.com/app/idYOUR_APP_ID"]];
}
In the simulator, this doesn't work. (Can't test it on a real device right now)
Is this the correct way to do this or should I try something else?
Your code is correct for launching the App Store with the app page open; I use the same code in my shipping app. This is the best you can achieve on iOS 7. It doesn't work on the iOS Simulator because the simulator doesn't have the App Store or iTunes apps installed, so there's nothing to launch.
Try using iRate. Handle all network connection and other related issues. And easy to implement. Just drag and drop files to your AppDelegate. It automatically configures all the required terms(like app store id, etc) from the info.plist files, and gets all the required information from app store.
NOTE: iRate can be used without any configuration, just by dragging and adding the files to project. See this example.
#import "iRate.h"
#implementation AppDelegate
+ (void)initialize
{
//configure iRate
[iRate sharedInstance].previewMode = YES;// yes for testing
}

Resources