Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all 58056 articles
Browse latest View live

Best practice for integrating Connectivity Plugin in Xamarin.Forms???

$
0
0

The Connectivity Plugin is working for me, but it is doing too good of a job. What I mean by that is the way in which I have implemented the plugin causes multiple alerts to fire when the app loses the WiFi connection.

Let's say that I have 15 pages in my app. I have implemented the following check in the main method of each page. As you can see, when a change is detected, if should fire off an alert and push the SignIn Page onto the stack.

CrossConnectivity.Current.ConnectivityChanged += async delegate (object sender, Plugin.Connectivity.Abstractions.ConnectivityChangedEventArgs e)
            {

                if (e.IsConnected == false)
                {
                    await DisplayAlert("Connectivity Alert", ValidationResources.NotConnectedMessage3, "OK");
                    this.IsBusy = true;
                    await Navigation.PushAsync(new SignIn());
                    this.IsBusy = false;
                }

            };

If 8 of the pages are on the stack, then I get 8 alerts when a change is detected. This is a horrible user experience.

I see how this guy has implemented his solution in the App.cs file, but I don't see how he can then alert the user that something has happened.

https://forums.xamarin.com/discussion/51735/notification-to-pcl-when-wifi-state-changed

With my method, should I clear the stack before I push the a new SignIn Page? Is there a better approach to managing this?

By the way, I also implement this method in all my Command initiated ViewModel methods. This will check to make sure the user is connected before making a request to the remote API, for example.

 if (CrossConnectivity.Current.IsConnected == false)
            {
                NetworkAlert = ValidationResources.NotConnectedMessage2;
                var notificator = DependencyService.Get<IToastNotificator>();
                await notificator.Notify(ToastNotificationType.Warning, "Connectivity Alert", NetworkAlert, TimeSpan.FromSeconds(3));
                IsBusy = false;
                return;
            }

Any help is much appreciated. Thanks!


Unable to update Xamarin.Form to v2.5 in Xamarin.Android

$
0
0

Hi All. Currently I'm using Visual Studio 2017 version 15.5. I trying to upgrade my nuget Xamarin.Form from v2.3.4.231 to v2.5.
Portable project and Xamarin.iOS upgraded successsfully, but failed on Xamarin.Android. It will rolling back to previous version and shows error message "The Collection is read-only".
Thanks in advance for those who can point out my mistakes. :)

[Prism] Navigate to another page from OnNavigatingTo()

$
0
0

I am trying to understand how navigation works in Prism.
I have this code in Page1:

        public override async void OnNavigatingTo(NavigationParameters parameters)
        {
            base.OnNavigatingTo(parameters);
            await NavigationService.NavigateAsync("Page2");
        }

and even tho I hit the line await NavigationService.NavigateAsync("Page2"); it does not redirect me to that page.
After that line, the code is still hitting the event OnNavigatedTo(NavigationParameters parameters), which causes the current page to load.

I verified that the Page2 constructor (the view model) is executed, so i don't understand why Page1 is still reloaded.

How can I navigate from Page1 to Page2 without showing Page1?

I am doing this because my app can switch user role (Client/Guest), and when I do I need to navigate to the root (to do stuff) and then redirect to a different page.

Can I create a control through binding?

$
0
0

Hi Experts,

I have a control that is a parent to an arbitrary number of buttons. I want to create those buttons based on binding to a property in my viewmodel.
can someone point me in the right direction>

Thanks in Advance

percy

Xamarin.Forms example code don't deploy into android device emulator

$
0
0

Hi,
I am newbie about xamarin and I need understand why the deploy process take a looong time to move my apk app to emulated device.
I am using

  • VS2017 15.6.4
  • Xamarin 4.9.0.752
  • Xamarin Designer -4.10.58
  • Xamarin.Android.SDK 8.2.0.16
  • Xamarion.iOS and Xamarin.Mac SDK 11.8.1.28
  • XamarinCRM - Android example (Xamarin Forms)

After be waiting for one hour I decided going to the option Build-> Cancel and stop the deploy: This is the output: from build window:

1>C:\Program Files (x86)\Android\android-sdk\build-tools\27.0.3\zipalign.exe 4 "C:\Users\rolando\Downloads\app-crm-master\app-crm-master\src\MobileApp\XamarinCRM.Android\obj\Debug\android\bin\com.xamarin.xamarincrm.apk" "bin\Debug\com.xamarin.xamarincrm-Signed.apk"
1>C:\Program Files (x86)\Android\android-sdk\build-tools\27.0.3\apksigner.BAT sign --ks "C:\Users\rolando\AppData\Local\Xamarin\Mono for Android\debug.keystore" --ks-pass pass:android --ks-key-alias androiddebugkey --key-pass pass:android --min-sdk-version 17 --max-sdk-version 27 bin\Debug\com.xamarin.xamarincrm-Signed.apk
1>Done building project "XamarinCRM.Android.csproj" -- FAILED.
1>
1>Deploy failed on VisualStudio_android-23_arm_phone
1>Process was cancelled
Build has been canceled.

Bindings, bindings, bindings - Its doin' my 'ead in!!

$
0
0

Ive taken a piece of code from the forum and worked it into my project:

var dirName = new Entry()
{
                Text = "",
                BackgroundColor = Color.White,
                TextColor = Color.Black,
                HeightRequest = 40,
                WidthRequest = 140,
                HorizontalOptions = LayoutOptions.FillAndExpand
 };
 string item = "foo";
 dirName.BindingContext = item;
 dirName.SetBinding(Entry.TextProperty, ".", BindingMode.TwoWay);

Now, although the string 'foo' appears in the entry 'dirname' when I open the form, changes to that entry do not update the item variable which is really what Im looking for.

Why is that? Any help is greatly appreciated..!

when is OnTrimMemory called in Android?

$
0
0

I had logged event on when OnTrimMemory memory is called in my app and i am seeing this method is called very often. is that something I should worry about? i though first that it is an method called only when memory usage is high and available memory is low but apparently thats not the case. i logged on my own phone to see what is the memory usage and available memory at the time when this method is called and I am seeing that memory usage is in acceptable level and available memory.

DeviceInfo plugin, iOS, and TestFlight?

$
0
0

I am using @JamesMontemagno 's great DeviceInfo plugin to get the device info. It works fine for Android. I get a unique Id (CrossDeviceInfo.Current.Id) for each device whether I deploy it directly or via HockeyApp for testing.

However, I get a different device id for iOS depending on if I have the app running in debug mode through the mac (Xamarin.iOS build host) or TestFlight. Is there any reason why I should be getting a different device id when I have installed this app using TestFlight?

Is there a better method for getting the unique device id? I need the device id to add as a tag to Notification Hub.


Push for Ad-Hoc (production) release - aps-environment *still* always resetting to development

$
0
0

Hi,

Xamarin Forms Project (Windows 10)
Visual Studio 2017 Version 15.6.4
Connected to Mac High Sierra over Network

My app deployed to my iOS device perfectly in development, and push notifications work fine.

I created a new certificate for iOS Distribution.
I created a new certificate for Apple Push Services.
I created a new provisioning profile (distribution)
Downloaded everything into Xcode on the mac.

I am trying to build (Visual Studio 2017) Ad-Hoc build, with IPA, so that I can deploy it via AppLoader to itunesconnect and set it up in TestFlight.

I am building this Ad-Hoc with the Distribution Signing identity and Provisioning Profile.

No matter what I do, in the file Entitlements.plist, the value of aps-environment changes to development, and to appLoader refuses to upload the IPA.

Help? Am I doing something obviously wrong here?

Thanks

Geolocator only works after exiting and re-entering app

$
0
0

The Xamarin.Forms application I'm working on is trying to prompt the user for location permissions on initial app startup, and then get their GPS position afterwards. iOS works fine, but when it runs on Android the permission prompt appears, the user clicks "allow," and then the CrossGeolocator.Current object says that the IsGeolocationAvailable and IsGeolocationEnabled properties are false. When the user closes and reopens the app, both are enabled. Is there a way for the CrossGeolocator.Current to recognize that it just got location permissions and that it should update?

What I've got so far:

Geolocator Plugin v3.0.4
Android Target v25

ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION set in Manifest

Current activity set in MainActivity's OnCreate:

Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity = this;

OnRequestPermissionsResult handler in MainActivity:

public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)
        {
            PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);
        }

Prompts user for location permissions and then gets GPS position:

using Plugin.Geolocator;
using Plugin.Geolocator.Abstractions;
using Plugin.Permissions;
using Permissions = Plugin.Permissions.Abstractions;
using Xamarin.Forms;
.
.
.
    System.Threading.Tasks.Task.Factory.StartNew(
                    async () =>
                    {
                        await CheckAndEnableGeoLocatorPermissions();
                    });

                if (CurrentGeoLocator.IsGeolocationAvailable
                    && CurrentGeoLocator.IsGeolocationEnabled)
                {
                    CurrentGeoLocator.GetPositionAsync(TimeSpan.FromSeconds(Constants.IntervalTime.GetGeoLocatorCurrentPosTimeOut)).ContinueWith(
                        x =>
                        {
                            CurrentPosition = x.Result;
                        });
                }
.
.
.__
private async System.Threading.Tasks.Task CheckAndEnableGeoLocatorPermissions()
        {
            try
            {
                var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permissions.Permission.Location);
                if (status != Permissions.PermissionStatus.Granted)
                {
                    var results = await CrossPermissions.Current.RequestPermissionsAsync(Permissions.Permission.Location);
                    //Best practice to always check that the key exists
                    if (results.ContainsKey(Permissions.Permission.Location))
                    {
                        status = results[Permissions.Permission.Location];
                    }
                }

                if (status != Permissions.PermissionStatus.Granted && status != Permissions.PermissionStatus.Unknown)
                {
                    Device.BeginInvokeOnMainThread(() => UserDialogs.Instance.Alert(
                        Text.Error_LocationPermissionDenied));
                }
            }
            catch (Exception ex)
            {
                Device.BeginInvokeOnMainThread(() => UserDialogs.Instance.Alert(ex.Message));
            }
        }

Exception while loading assemblies: netstandar issue!

$
0
0

Hi everyone,

I am working on a project and a couple of days ago, I have not been able to execute the application since it sent me the following error:

Error Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'netstandard.dll'
at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters)
at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(DirectoryAssemblyResolver resolver, ICollection`1 assemblies, AssemblyDefinition assembly, Boolean topLevel)
at Xamarin.Android.Tasks.ResolveAssemblies.Execute(DirectoryAssemblyResolver resolver) AnconApp.Android C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets 1413

I tried:
1. Update Visual Studio 2017 to the lastest version (15.6)
2. Update NugetPackage Components
3. Delete and reload NugetPackage Components
4. Install VS 2015 and build the app
5. Clear, build and rebuild the solution.

But nothing can delete the error.

Anybody have the same issue and solved?

Any Help?

Navigation Page in TabbedPage Open New Navigation Page cannot show BackButton

$
0
0

As title, i want to open a navigation page when navigation page listview in tabbedpage.
var home = new NavigationPage(new HomePageCS());
home.Title = "Home";
home.BarBackgroundColor = Color.White;
home.BarTextColor = Color.Black;

            var discover = new NavigationPage(new DiscoverPage());
            discover.Title = "Discover";
            discover.BarBackgroundColor = Color.White;
            discover.BarTextColor = Color.Black;

            var notification = new NavigationPage(new NotificationPageCS());
            notification.Title = "Message";
            notification.BarBackgroundColor = Color.White;
            notification.BarTextColor = Color.Black;

            var profile = new NavigationPage(new ProfilePageCS());
            profile.Title = "Profile";
            profile.BarBackgroundColor = Color.White;
            profile.BarTextColor = Color.Black;

            Children.Add(home);
            Children.Add(discover);
            Children.Add(notification);
            Children.Add(profile);


    var notification = new NavigationPage(new DetailPageCS(item));
                    notification.Title = "Message";
                    notification.BarBackgroundColor = Color.White;
                    notification.BarTextColor = Color.Black;
                    NavigationPage.SetBackButtonTitle(this, "Test");
                    NavigationPage.SetHasBackButton(notification, true);
    await Navigation.PushAsync(notification);
    await Navigation.PushModalAsync(new DetailPageCS(item));

Error: “com.facebook.sdk.login error 308” in Xamarin.Form

$
0
0

I am using Visual Studio 2017. I am trying to connect with Facebook using following code by not able to connect. Can any body please suggest me what I missing? I have tried many solution but none of them work.

public void LogInToFacebook()
{
    if (AccessToken.CurrentAccessToken == null)
    {
        ObtainNewToken(LogInToFacebook);
        return;
    }
}

Getting Error: The operation couldn’t be completed. (com.facebook.sdk.login error 308.)
private readonly string[] permissions = { "public_profile", "email", "user_birthday", "user_photos" };
private void ObtainNewToken(Action callback)
{
var login = new LoginManager();

        login.LogInWithReadPermissions(permissions, null, (r, e) =>
        {
            if (e == null && !r.IsCancelled)
                callback?.Invoke();
            else
                HandleError(e?.LocalizedDescription);
        });
    }

info.plist: Facebook Related content

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>myapp.com</key>
        <dict>
            <key>NSTemporaryExceptionMinimumTLSVersion</key>
            <string>TLSv1.0</string>
            <key>NSTemporaryExceptionRequiresForwardSecrecy</key>
            <false/>
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
        <key>facebook.com</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
        <key>fbcdn.net</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
        <key>akamaihd.net</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
            <false/>
        </dict>
    </dict>
</dict>

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>fbapi</string>
    <string>fbapi20130214</string>
    <string>fbapi20130410</string>
    <string>fbapi20130702</string>
    <string>fbapi20131010</string>
    <string>fbapi20131219</string>
    <string>fbapi20140410</string>
    <string>fbapi20140116</string>
    <string>fbapi20150313</string>
    <string>fbapi20150629</string>
    <string>fbauth</string>
    <string>fbauth2</string>
    <string>fb-messenger-api20140430</string>
    <string>fb-messenger-api</string>
    <string>fbshareextension</string>
</array>
<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>fb90000000000</string>
        </array>
        <key>CFBundleURLName</key>
        <string>facebook</string>
    </dict>
</array>
<key>FacebookAppID</key>
<string>8000666666666</string>
<key>FacebookDisplayName</key>
<string>MyApp – Test</string>

Cocossharp in Xamarin forms

$
0
0

i have searched over the internet to learn about cocossharp game development, how the layer,objects,collision... works and other.

but i cant able to find ,i can see only the examples , in that example itself i can see lot of calculations and it was confusing me a lot..

please help me to learn about cocossharp

Native views and VS2017 intellisense not working

$
0
0

Today I found out about Native Views, awesome!
However, my intellisense is not working for this. It works fine except for inside the native xaml.

My xmlns declarations:

xmlns:ios="clr-namespace:UIKit;assembly=Xamarin.iOS;targetPlatform=iOS"
xmlns:androidWidget="clr-namespace:Android.Widget;assembly=Mono.Android;targetPlatform=Android"
xmlns:formsAndroid="clr-namespace:Xamarin.Forms;assembly=Xamarin.Forms.Platform.Android;targetPlatform=Android"
xmlns:win="clr-namespace:Windows.UI.Xaml.Controls;assembly=Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime;targetPlatform=Windows"

My xaml controls:

<ios:UISwitch On="{Binding Path=IsSwitchOn, Mode=TwoWay, UpdateSourceEventName=ValueChanged}"
                    OnTintColor="{x:Static ios:UIColor.Red}"
                    ThumbTintColor="{x:Static ios:UIColor.Blue}" />
<androidWidget:Switch x:Arguments="{x:Static formsAndroid:Forms.Context}"
                            Checked="{Binding Path=IsSwitchOn, Mode=TwoWay, UpdateSourceEventName=CheckedChange}"
                            Text="Enable Entry?" />
<win:ToggleSwitch Header="Enable Entry?"
                        OffContent="No"
                        OnContent="Yes"
                        IsOn="{Binding IsSwitchOn, Mode=TwoWay, UpdateSourceEventName=Toggled}" />

Intellisense stops after <ios: and the other platforms. It seems it can see the xmlns but not what's inside.

When I run the app it works great, I get different controls for each platform.
Im using VS2017, 15.3.4 and tested Xamarin.Forms 2.3.4.270 / 2.4.0.269-pre2 (nuget).

Anyone else experiencing this? Or is this just not supported?


Picker Renderer Affecting Behavior Without Any Additional Code

$
0
0

I was trying to apply a custom render to Picker when I realized the renderer affects the behavior of the Picker on Android platforms even without any additional code, i.e.

public class CustomPickerRenderer : PickerRenderer
{
    public CustomPickerRenderer(Context context) : base(context)
    {
    }
}

Without the renderer, the picker displays a full screen of options:

After renderer is applied, it looks like this:

Why is this the case and how can I apply a custom renderer while preserving the original behavior?

Set height in Toolbar xamarin froms

$
0
0

Hi i want to define Height in Toolbar, how hi can do this.

This is my code:

ContentPage.ToolbarItems >

<ToolbarItem Text="Botão 1" Clicked="OnClickButtonOne" Order="Secondary" />
<ToolbarItem Text="Botão 2" Clicked="OnClickButtonTwo" Order="Secondary" />
<ToolbarItem Text="Botão 3" Clicked="OnClickButtonThree" Order="Primary" Icon="cloud.png" />
<ToolbarItem Text="Botão 3" Clicked="OnClickButtonThree" Order="Primary" Icon="edit.png" />
<ToolbarItem Text="Botão 3" Clicked="OnClickButtonThree" Order="Primary" Icon="incomingmail" />
<ToolbarItem Text="Botão 3" Clicked="OnClickButtonThree" Order="Primary" Icon="list.png" />
<ToolbarItem Text="Botão 3" Clicked="OnClickButtonThree" Order="Primary" Icon="replayarrow.png" />
<ToolbarItem Text="Botão 3" Clicked="OnClickButtonThree" Order="Primary" Icon="settings.png" />
<ToolbarItem Text="Botão 3" Clicked="OnClickButtonThree" Order="Primary" Icon="signal.png" />
<ToolbarItem Text="Botão 3" Clicked="OnClickButtonThree" Order="Primary" Icon="search.png" />

</ContentPage.ToolbarItems>

Joining a bunch of controls

$
0
0

Sorry if this is a very basic question, but I don't know how is the name of the control or if I have to do a view, a subpage or a layout.

The point is that I have a bunch of controls (an entry, a delete button for the entry, and a listview) and variables that I want to encapsulate as a new control or something, to use with other pages once or more times. But I don't know what kind of element should I use to do it. If you could point me in the right way, I will do my researchs.

Also, I have to bind the listview with a list that can be one of the different models I have in my app, with different types of variables in it. Am I wrong or this is the time when I have to use a converter?

Thank you.

Silent remove of Page in Navigation Stack

$
0
0

Is there a way to move from one page to another but remove the last page I was on from the navigation stack.

For example

Page 1 > Page 2 > Page 3

As I move from Page 2 to Page 3, remove Page 2 from the navigation stack so when I go back it goes to page 1.

I know I can manually remove things from the navigation stack but it causes all kinds of weird animations when going back. Also if I do a Pop then a Push, it shows the animation on screen which I don't want.

So I am wondering if there is a way to remove it from the Stack silently, with no onscreen animations or quick flashes of the page etc visible to the user?

Real Time Vehicle Tracking Using Xamarin Forms

$
0
0

I am working on a task to track a vehicle (Cab)from mobile app which is to be built in Xamarin forms. Planning to Use GeoLocator plugin. Any ideas and suggestion how should i proceed.

I wish to show the vehicle moving on the map route when the user is actually tracking the ride.

How to get the best routes for a particular destination?

A device is installed in the vehicle which keeps sending the GPS Location.

Ideas and Suggestions are welcome.

Viewing all 58056 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>