I couldn't find any documentation on using RevenueCat bindings in Xamarin Forms, or any examples. How to get started? I think it's supposed to be obvious, but it wasn't for me.
Answering my own question below, I've made a small start, haven't tested any code yet. Please feel free to expand or correct.
This is for Xamarin Forms iOS on Visual Studio 2022 for Mac; MAUI could be similar.
In your iOS project, add the Nuget packages Xamarin.RevenueCat.iOS and Xamarin.RevenueCat.iOS.Extensions.
[Edit] I removed my suggestion to bind the Swift library, as it does not seem to be necessary.
A few sample code lines:
using RevenueCat;
using Xamarin.RevenueCat.iOS.Extensions;
....
RCPurchases.DebugLogsEnabled = true;
RCPurchases.ConfigureWithAPIKey( "my api key" );
RCPurchases.SharedPurchases.AllowSharingAppStoreAccount = true;
RCCustomerInfo purchaserInfo = await RCPurchases.SharedPurchases.RestoreTransactionsAsync ();
RCOfferings offerings = await RCPurchases.SharedPurchases.GetOfferingsAsync ();
Related
I'm trying to develop a class library for use from Uno Platform applications that can be distributed as a NuGet package. In the code, I need to be able to extract various information about the device currently running the code. I already figured out how to get the screen dimensions but now I'm stuck in getting the current operating system and version. I have seen code like this:
#if __ANDROID__
os = "android";
#elif __IOS__
os = "ios";
#endif
But as I understand, this is not supported in class libraries. I have also experimented with the Uno port of Xamarin.Essentials to use the DeviceInfo class. I couldn't get this to work, though.
Any help would be appreciated.
I approach getting the OS info in a different manner. I grab the OS info using the following code:
public static string getOSVersion()
{
string osInfo = Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily.ToString();
int dotPosition = osInfo.IndexOf('.');
string shortOsInfo = osInfo.Substring(0, dotPosition);
return shortOsInfo + " " + Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamilyVersion.ToString();
}
If you are on Android- it will return Android 11, on IOS it will return iOS 14.4(Keep in mind the version number will probably be different- just using it for example purposes). I have not run this on WASM, UWP, Linux, or MacOS- but it should work. Hopefully this will be helpful to you!
My app uses Xamarin.Forms.Maps to display a map and also for geocoding. The map is displayed on a separate page when the user navigates to it from the main page. I use the geocoder to reverse geocode the current location so that I have the address. This is done from various places other than the map page.
When I run the app on a device (even in debug mode) the geocoder works right away in iOS and Android, but does not work in UWP. After I navigate to the map page and display the map, then go back to a different page to use the geocoder it starts working.
I saw a thread about the map not working with release build so I added the following code:
var laRendererAssemblies = new[] { typeof(Xamarin.Forms.Maps.UWP.MapRenderer).GetTypeInfo().Assembly };
Xamarin.Forms.Forms.Init(e, laRendererAssemblies);
//Xamarin.Forms.Forms.Init(e);
Xamarin.FormsMaps.Init("MyBingMapsKey");
This has not helped the issue with the Xamarin.Forms.Maps.Geocoder. I also tried creating an instance of Xamarin.Forms.Maps.Map in my main page, but that did not help either. Is there a way to prime the map component so that the Geocoder will work on a device? (My test device is ARM, but it happens when I run on Local
Machine (Win 10) too)
Following is a snippet of the call to the Geocoder (which works fine once the user has navigated to the Map page and back - and it works fine in iOS and Android - and as such I don't believe it is a problem with the code, but here it is):
public static async Task<Plugin.Geolocator.Abstractions.Position> Geocode(string address)
{
try
{
var loGeocoder = new Xamarin.Forms.Maps.Geocoder();
System.Diagnostics.Debug.WriteLine("Get Lat/Lon");
var lcolPositions = await loGeocoder.GetPositionsForAddressAsync(address);
if (lcolPositions != null)
After doing some research and ensuring that your geodecode class being static wouldn't mess with the async/await pattern in the UWP build. I've come across a few references to this particular problem with the built in Forms.Map geodecoder elsewhere, not just for UWP it has also been noted for android‡.
I took some time to have a look at one of our current cross-platform applications that we have in the app stores, and according to our internal documentation we switched out both the xamarin.forms map, and the geodecoder for custom ones.
The plugin that we use for our cross-platform application is the 'GelocatorPlugin' created by james montemagno, and can be found here.
It can be added to your project as a Nuget package if you prefer, and the implementation of it is very similar to the default one, so there's very little code to change. The primary benefit is that the UWP element of the geodecode plugin has been modified to take into account windows advanced tracking scenarios (details found here).
It should be a lot more stable than the one your using, once installed you simply use it like so:
Reverse Geocoding
Based on a location that is passed in, thi swill grab a list of
addresses.
UWP requires a Bing Map Key, which you can acquire by reading this
piece of documentation.
try
{
var addresses = await locator.GetAddressesForPositionAsync (position, string mapKey = null);
var address = addresses.FirstOrDefault();
if(address == null)
Console.WriteLine ("No address found for position.");
else
Console.WriteLine ("Addresss: {0} {1} {2}", address.Thoroughfare, address.Locality, address.Country);
}
catch(Exception ex)
{
Debug.WriteLine("Unable to get address: " + ex);
}
‡ Links to similar problems - Link 1, Link 2
resolved after added following lines in APP.xaml.cs (UWP project)
Xamarin.FormsMaps.Init("bingmapkey");
Windows.Services.Maps.MapService.ServiceToken = "bingmapkey";
Yesterday I got the update for Android 5.0 on my Nexus 4, and the altbeacon library stopped detecting beacons. It appears that didEnterRegion and didRangeBeaconsInRegion are not even getting called when monitoring and ranging, respectively.
Even the Locate app from Radius Networks behaves differently now, the values from beacons, once they are detected, doesn't get updated anymore and often it appears as if the beacons went out of range.
One thing I noted differently, is that now in the logcat it appears the following line "BluetoothLeScanner﹕ could not find callback wrapper". I went ahead and looked for that class and saw that it was introduced with Android L, but I don't know if that has something to do with it.
It's important to say that before the update I had been working with both the Locate app and the Reference Application without any trouble.
I don't know if this is a generalized problem or not, but if it happened to me I'm sure it could happen to someone else, so any help it would really be appreciated.
Thanks in advance!
UPDATE:
After failing at getting the library to work I decided to try the Android L branch of the library. What I did was that I plugged in the new library into the Reference App, but didn't work as expected either.
The Monitor Activity seems to be working ok by notifying when the device has entered a new region. However, the Ranging Activity doesn't report any beacons, although didRangeBeaconsInRegion is getting called, always report zero beacons. Curiously, when the activity is paused (switching momentarily to another app) the logcat shows that now didRangeBeaconsInRegion does get called with actual beacons.
I'm kind of stuck right now because I don't know how to get any of libraries working on Android L, so again, any help would really be appreciated.
I'm using the latest Altbeacon build on 5.0+ and have no problem with it. in fact, I never used it on kitkat so i'm not really sure i can help but here is my working code which listen to iBeacons.
implement beaconConsumer:
public class MainActivity implements BeaconConsumer
init BeaconManager
beaconManager = BeaconManager.getInstanceForApplication(this);
if (beaconManager != null && !beaconManager.isBound(this)) {
beaconManager.getBeaconParsers().add(new BeaconParser().
setBeaconLayout("m:0-3=4c000215,i:4-19,i:20-21,i:22-23,p:24-24"));
beaconManager.bind(this);
}
onConnect and start listner
#Override
public void onBeaconServiceConnect() {
beaconManager.setRangeNotifier(new RangeNotifier() {
#Override
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
if (beacons.size() > 0) {
Beacon firstBeacon = beacons.iterator().next();
}
}
});
beaconManager.startRangingBeaconsInRegion(new Region("com.example.app", null, null, null));
}
this code is working on 3 devices
Nexus 4 5.0.1
Samsung Galaxy s4 - Stock 5.0.1
Samsung Galaxy s4 - CM12 5.1.1
Old question, but maybe some people will try to find answer for higher systems where you have to ask for permissions. You need to ask for Manifest.permission.ACCESS_FINE_LOCATION before scanning. At least that was the problem I met. In my opinion lib should crash such cases at least and indicate the problem
My below code worked fine while running in .NET 4.0 but when I run the same code in .NET 2.0 I am getting an error at var I found that var is not accepted in .NET 2.0 and older but my Plesk 9.0.1 do not allow me to use .NET 4.0 also I cannot upgrade my plesk at this time because of traffic to my server. Well, anybody please convert the below code such that is works even with .NET 2.0. Thanks in advance.
var app = new hMailServer.Application();
app.Authenticate("Administrator", "********");
var domain = app.Domains.get_ItemByName("mydomain.ext");
var account = domain.Accounts.Add();
account.Address = "user#mydomain.ext";
account.Password = "secret";
account.Active = true;
account.MaxSize = 1000;
account.PersonFirstName = "";
account.Save();
Just instead of var what can I use? I tried string which is not accepted. Any idea?
First line I used as hMailServer.Application app = new hMailServer.Application(); Its accepted bur at the var domain and var account .NET 2.0 is not accepting.
Just instead of var what can I use?
Use the actual types (read the documentation of the API you are using to understand what those types are):
hMailServer.Application app = new hMailServer.Application();
app.Authenticate("Administrator", "********");
hMailServer.Domain domain = app.Domains.get_ItemByName("mydomain.ext");
hMailServer.Account account = domain.Accounts.Add();
...
Also note that var was introduced in C# 3.0 and not 4.0.
Basically you need to identify the type of your variables and then declare them.. you could do it by hovering over the variable and visual studio should show you the return type or the type of variable it is.
Or install Resharper (a productivity tool) for visual studio it should assist you with the same.. You can do things like pull out variable for a particular piece of code and it will take care of identifying the type etc of your varaible.. You should be able to get a trial version.
You might have to do this en masse that is why I am suggesting this.
P.S: I am not markerting Resharper.. just a regular user of the software and in awe of the same.
I been looking for a twitter lib for my ASP.NET NET MVC 3 software, but I need to implement the REST API functions that I nor found in Twitter Helper or Twitterizer. Rest API allow me to use a Find People query.
There is another one could solve my problem?
My suggestion would be to try looking into a library, such as TweetSharp that already has wrappers around a substantial amount of the Twitter API methods. If that doesn't work for you, consider writing your own wrapper around the methods you need using libraries such as HammockRest or RestSharp that have support for working with http, oauth and other such features that may assist you.
Looking better in Twitterizer I found what I need, perform Search People, and other functions. I recommend Twitterizer to use twitter in ASP.NET MVC 3, ´cause the oAuth process has a better code.
Here the Sample code to peform Search People in twitter using Twitterizer :
UserSearchOptions options = new UserSearchOptions();
options.NumberPerPage = 40;
options.Page = 1;
TwitterResponse<TwitterUserCollection> usersResponse = TwitterUser.Search(tokens,pesquisa.Conteudo,options);
if (usersResponse.Result == RequestResult.Success)
{
StringBuilder list = new StringBuilder();
foreach (var u in usersResponse.ResponseObject)
{
list2.Append(u.Name + "-" + u.Id);
}
ViewBag.Result_Twitter = list.ToString();
}