Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all 204402 articles
Browse latest View live

Can't use App.Repl() with newest update

$
0
0

I'm having an issue with the newest version of Xamarin.UITest on iOS, when calling Repl().
I get the following error message: "Only iOS v9 and later is supported when using Xcode v8"

But I'm using Xcode 9.1 and iOS 11.1 and have tried 11.2 too.

Any ideas?


OnDisappearing not firing when awaiting completion result when Navigation.ModalStack.Count > 1

$
0
0

Good Afternoon,

In Latest Xamarin Forms, running through on an Android build I have a behaviour that I cannot find documented.

The stack looks like this:

Navigation Form
└ Modal-0
└Modal-1 <- Active

The top most (Modal-1) the OnDisappearing() is being fired as expected.

However, the result of that form which is awaited upon from the Modal-1 will also close also Modal-0. OnDisappearing does not fire on Modal-0 when it is popped, meaning the underlying Navigation form (which also awaits the result) sits indefinitely waiting for a result that doesn't occur.

I have simplified the code in to an example, and there are application flow reasons in using OnDisappearing to set the completion task, but I am stuck on explaining this behaviour.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace Steps
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class SomeModalClass : ContentPage
{
public SomeModalClass()
{
InitializeComponent();

        _TaskCompletionSource = new System.Threading.Tasks.TaskCompletionSource<StepResult>();

        this.Title = String.Format("Model-{0}", Navigation.ModalStack.Count);
    }

    private async void GetAnswerFromNextPage_Clicked(object sender, EventArgs e)
    {

        SomeModalClass mModal = new SomeModalClass();
        await Navigation.PushModalAsync(mModal);
        var mResult = await mModal .PageClosedTask;

        _Result = mResult;
        await Navigation.PopModalAsync(false);
    }

    private async void ButtonYes_Clicked(object sender, EventArgs e)
    {
        _Result = StepResult.Yes;
        await Navigation.PopModalAsync(false);
    }

    private async void ButtonNo_Clicked(object sender, EventArgs e)
    {
        _Result = StepResult.No;
        await Navigation.PopModalAsync(false);
    }


    protected override void OnDisappearing()
    {
        base.OnDisappearing();

        if (_Result != StepResult.None)
        {
            _TaskCompletionSource.SetResult(_Result);
        }

    }

    public Task<StepResult> PageClosedTask { get { return _TaskCompletionSource.Task; } }
    private TaskCompletionSource<StepResult> _TaskCompletionSource { get; set; }


    private StepResult _Result;

    public StepResult Result { get => _Result; set => _Result = value; }


}

}

Socket IO

$
0
0

I have to make a chat for a Xamarin Forms (PCL) application. I'm using the NuGet package SocketIoClientDotNet for socket.

At first I could not connect at all. After many researches on internet I found this open issue on Github, so I downgraded the library but also all the dependencies:

  • EngineIOClient.Net V0.9.22
  • SocketIOClientDotNet V0.9.13
  • WebSocket4Net V0.14.1.0

After that it was better, the connection seemed to work but I encountered a new issue: the connection is very instable and it's difficult for me to test anything cause of that. One time it can connect multiple times, one time it not connect at all, it's very annoying...

My code is very simple:

Common Code:

ISocketIO interface:

public interface ISocketIO
{
    void Connect(string url);
    void On(string eventString, Action<object> action);
}

MsgService class:

readonly string EVENT_CONNECT = "connect";
public MsgService(ISocketIO socket)
{
    Socket = socket;

    if (Socket != null)
    {
        Socket.On(EVENT_CONNECT, () =>
        {
            (code here...)
        });
    }
}

public void Connect()
{
    if (Socket != null)
    {
        Socket.Connect("chat_url_here");
    }
}

App class:

public partial class App : Application
{
    public static MsgService MsgService;

    public App(ISocketIO socket)
    {
        InitializeComponent();

        Language = Language.FRENCH;
        MsgService = new MsgService(socket);
        MsgService.Connect();
        MainPage = new NavigationPage(new MainPage());
    }

    ...
}

iOS code (same for Android):

Class SocketIO

[assembly: Xamarin.Forms.Dependency(typeof(SocketIO))]
namespace MeetYou.iOS
{
    public class SocketIO : ISocketIO
    {
        Socket _socket;

        public void Connect(string url)
        {
            IO.Options opt = new IO.Options
            {
                Path = "path_here"
            };
            _socket = IO.Socket(url, opt);
            _socket.Connect();
        }
    }
}

AppDelegate:

[Register("AppDelegate")]
public class AppDelegate : Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
    public override bool FinishedLaunching(UIApplication uiApplication, NSDictionary launchOptions)
    {
        Xamarin.Forms.Forms.Init();
        LoadApplication(new App(new SocketIO()));

        return base.FinishedLaunching(uiApplication, launchOptions);
    }
}

Maybe I'm doing something wrong of maybe it exists an other plugin I could use instead this one.

Native Callback sometimes breaks the App after “GC_BRIDGE waiting for bridge processing to finish”

$
0
0

In our xamarin android application we capture images with the device camera and pass the image data to a native c++ library. The library does some asynchronous processing of the image. Once the processing is done the app gets notified over a callback method.
This usually works fine but sometimes the app freezes (all threads are stopped) and the last log entry is “GC_BRIDGE waiting for bridge processing to finish”. From the c++ side the call to the callback function does not return and we do not get into our c# callback method. However, the other c++ threads run further. It is somehow timing related as when we add a delay from about 1s before the callback is called it works fine.

As we suspect that the problem is related to the gc we tried all three available gc bridge implementations (old, new, tarjan) with the same result.

[StructLayout(LayoutKind.Sequential)]
public struct Notification
{
    [MarshalAs(UnmanagedType.FunctionPtr)]
    public PreviewReadyCallback PreviewReady;

    [MarshalAs(UnmanagedType.FunctionPtr)]
    public CalculationReadyCallback CalculationReady;

    [MarshalAs(UnmanagedType.FunctionPtr)]
    public ErrorCallback Error;
}

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void PreviewReadyCallback(int frame);

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void CalculationReadyCallback(int frame, int remainingFrames);

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void ErrorCallback(int frame, int status);

[DllImport(Wrapper.DllName)]
public static extern int Create(string path, Notification callbacks);

See also the attached logfile.

Versions:
Xamarin 4.7.10.38, 4.2.2.11
Xamarin.Android SDK 8.0.2.1, 7.0.2.42

Xamrin.Forms iOS ListView - ViewCell height is wrong ONLY on application start after fresh install

$
0
0

I have a xaml based ListView ViewCell with an image and 3 grid rows of text that is not rendering properly the FIRST TIME the application is started.

It is the first page of the application after logging in. When it does not render properly the content inside the ItemTemplate's ViewCell is clipped because the viewcell is too small, or if I change some properties the images will spill into the next row.

  • If you navigate to a new page (popping the problem page completely off the stack) and then come back it renders properly.
  • If you close the application and startup again, it renders properly.
  • I have only noticed this on smaller iPads and iPad simulators. Not a problem on large iPad. Probably an issue on phones but not verified.

It is so strange that the only time I can reproduce is after a fresh install and initial rendering.

I have tried many sizing configurations to remedy the issue but the only thing that works is setting the ViewCell's height explicitly. This would be fine except that the first row of Text is dynamic length, and so it seems to conflict with the whole HasUnevenRows paradigm.

Based on my research I know that in the past there were some issues with dynamic cell heights in forms on iOS, and that people had come up with workarounds involving creating custom view cells for each type of ListView ItemTemplate that needed it. I would prefer to avoid that since we have many other pages that use a similar layout and they render fine (perhaps because they are not the first page of the application). Also my understanding was that HasUnevenRows = true is now working in iOS and explicitly setting ViewCell height is not necessary.

Can anyone provide guidance on why this may be happening and if perhaps we just need to update some NuGet Packages? I am approaching a delivery so I am cautious to do so, but if that will fix it I will forge ahead.

Xamarin 4.6.0.299
Xamarin.iOS 7.4.0.21
Xamarin.Forms 2.3.4.267

I have posted the ListView xaml below for reference:

                <ListView.GroupHeaderTemplate>
                    <DataTemplate>
                        <ViewCell Height="18">
                            <Label Text="{Binding Key}"
                            IsVisible="{Binding Path=BindingContext.GroupingEnabled, Source={x:Reference myPage}}"
                            TextColor="White"
                            VerticalTextAlignment="Center"
                            VerticalOptions="FillAndExpand"
                            HorizontalOptions="FillAndExpand"
                            BackgroundColor="Black"
                            FontSize="Micro"/>
                        </ViewCell>
                    </DataTemplate>
                </ListView.GroupHeaderTemplate>
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <Grid RowSpacing="0">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="{StaticResource ImageGridLength}" />
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="50" />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*" />
                                    <RowDefinition Height="25" />
                                    <RowDefinition Height="25" />
                                </Grid.RowDefinitions>
                                <Grid Grid.Row="0" Grid.Column="0" Grid.RowSpan="3">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="{StaticResource ImageGridLength}" />
                                    </Grid.RowDefinitions>
                                    <Image Source="{Binding ImageUri}"
                                           Style="{StaticResource ListViewImageStyle}"
                                           Grid.Row="0"/>
                                </Grid>

                                <Label Text="{Binding Model.Description}"
                                   FontAttributes="Bold"
                                   FontSize="Medium"
                                   Grid.Row="0"
                                   Grid.Column="1"
                                   LineBreakMode="TailTruncation"
                                   Grid.ColumnSpan="2"
                                   TextColor="Black" />
                                    <Label Text="Name" Grid.Row="1" Grid.Column="1" FontAttributes="Bold" FontSize="Small" />
                                    <Label Text="{Binding Model.Name}"  Grid.Row="1" Grid.Column="2" FontSize="Small" />
                                    <Label Text="Number" Grid.Row="2" Grid.Column="1" FontAttributes="Bold" FontSize="Small" />
                                    <Label Text="{Binding Model.Number}" Grid.Row="2" Grid.Column="2" FontSize="Small" />

                                <Grid Grid.Row="1" Grid.Column="3">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="{StaticResource ImageGridLength}" />
                                    </Grid.RowDefinitions>
                                    <Image Source="Delete.png" IsVisible="{Binding Model.CanDelete}"
                                           Grid.Row="1" Grid.Column="2" Aspect="AspectFit" VerticalOptions="Center" HorizontalOptions="Center" HeightRequest="30">
                                        <Image.GestureRecognizers>
                                            <TapGestureRecognizer
                                              Command="{Binding BindingContext.DeleteModel, Source={x:Reference myPage}}"
                                              CommandParameter="{Binding}"/>
                                        </Image.GestureRecognizers>
                                    </Image>
                                </Grid>
                            </Grid>
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>

Xamarin shared code issue with dependency service

$
0
0

I have a project set up so that I can have a different styled for each of our clients
e.g.

  • PCL Project (shared code, Forms, etc)
  • Android.Shared (shared resources/localisations for the android apps/platform specific code)
  • Android.Client1Theme (custom resources (logos, colors, etc) for Client1)
  • Android.Client2Theme (custom resources (logos, colors, etc) for Client2)
  • iOS.Shared (shared resources/localisations for the android apps/platform specific code)
  • iOS.Client1Theme (custom resources (logos, colors, etc) for Client1)
  • iOS.Client2Theme (custom resources (logos, colors, etc) for Client2)

I have android working correctly by setting the dependencies for the Client1.droid project however the same setup for iOS isn't working and i get an issue with the dependency service getting a null reference when looking for my interface.

iOS.Shared dependencies =

  • PCL Project

iOS.Client1Theme dependencies =

  • PCL Project
  • iOS.Shared

PCL Code
DependencyService.Get<ISystemFunctions>().ToggleTorch();

Shared iOS project code

[assembly: Dependency(typeof(SystemFunctions_iOS))]
namespace ShareApp.iOS.iOS_Interfaces
{
    public class SystemFunctions_iOS : ISystemFunctions
    {
        public SystemFunctions_iOS()
        {   }

        public void ToggleTorch()
        {
            var device = AVCaptureDevice.GetDefaultDevice(AVMediaTypes.Video);
            if (device == null)
                return;

            device.LockForConfiguration(out NSError error);
            if (error != null)
            {
                device.UnlockForConfiguration();
                return;
            }
            else
            {
                device.TorchMode = device.TorchMode == AVCaptureTorchMode.On ? AVCaptureTorchMode.Off : AVCaptureTorchMode.On;
                device.UnlockForConfiguration();
            }
        }
    }
}

Xamarin.iOS and huge number of modules loaded

$
0
0

My crash dumps show that a huge number of modules are loaded in the process, 448 to be precise.
Some of them are actually used (like UIKit or Foundation), some must be system stuff (libSystem*) and some dependencies (like CoreGraphics).
Many of them I can't explain though, like Metal, CameraKit, ChatKit, EmojiKit.

Does Xamarin.iOS import all of those modules, regardless if they're used of not? That's the only explanation I have.

AVCaptureVideoDataOutputSampleBufferDelegate stops after 1 - 3 seconds

$
0
0

Hi
I am trying to capture an MJPEG stream (this is a requirement) using AVCaptureVideoDataOutputSampleBufferDelegate.
After few seconds the AVCaptureVideoDataOutputSampleBufferDelegate.DidOutputSampleBuffer overrider is not called any more.
The video preview on the UI is working OK.
I am building with Xamarin.Forms version 2.5.0.121934, Xcode 9.2 (I have also tried with Xcode 9.1) and I have tested on both iOS 11.1.2 and 11.2

Note I have already implemented (and working) capturing the pictures with AVCaptureStillImageOutput but I am moving to capturing Video since on iOS 11.2 a shutter sound is played on every captured image generating many tik sounds.

I setup the video capture by using the following code:

    AVCaptureSession captureSession = new AVCaptureSession
        {
            SessionPreset = AVCaptureSession.PresetMedium
        };

        AVCaptureVideoPreviewLayer previewLayer = new AVCaptureVideoPreviewLayer(captureSession)
        {
            VideoGravity = AVLayerVideoGravity.ResizeAspectFill,
            Frame = Bounds
        };

        AVCaptureDevice captureDevice = null;
        AVCaptureDevice[] devices = AVCaptureDevice.DevicesWithMediaType(AVMediaType.Video);
        if (devices != null)
        {
    //  Find the preferred capture device
        }

        if (captureDevice == null)
        {
            return false;
        }

        AVCaptureDeviceInput captureInput = AVCaptureDeviceInput.FromDevice(captureDevice);
        if (captureInput == null)
        {
            return false;
        }

            CVPixelBufferAttributes settings = new CVPixelBufferAttributes
            {
                PixelFormatType = CVPixelFormatType.CV32BGRA
            };

            AVCaptureVideoDataOutput outputVideo = new AVCaptureVideoDataOutput { WeakVideoSettings = settings.Dictionary };
            outputVideo.AlwaysDiscardsLateVideoFrames = true;

            DispatchQueue queue = new DispatchQueue("myQueue");
            OutputRecorder outputRecorder = new OutputRecorder(this);

            outputVideo.SetSampleBufferDelegateQueue(outputRecorder, queue);


        captureSession.AddInput(captureInput);
        captureSession.AddOutput(outputVideo);

        Layer.AddSublayer(previewLayer);

captureSession.StartRunning();


        captureSession.StartRunning();

The AVCaptureVideoDataOutputSampleBufferDelegate.DidOutputSampleBuffer overrider is also quite simple

        public override void DidOutputSampleBuffer(AVCaptureOutput captureOutput, CMSampleBuffer sampleBuffer, AVCaptureConnection connection)
        {
            try
            {
                UIImage image = ImageFromSampleBuffer(sampleBuffer);

                NSData jpegData = image.AsJPEG();
                byte[] bytes = jpegData.ToArray();

                lock (m_Owner.m_syncState)
                {
                    m_Owner.m_LastCapturedFrame = bytes;
                }

                jpegData.Dispose();
            }
            catch (Exception ex)
            {
                DammLogger.Log(DammLoggerLevel.Warn,TAG, ex, "Error getting the video image");
            }
            finally
            {
                sampleBuffer.Dispose();
            }
        }

Have somebody any hint about what I am doing wrong ?


Page do not redirect after successful Oauth2 in Android

Help with proper timing, please

$
0
0

Hi all,
Currently I am working on app... nothing special really... in a kind. I am using a single page, periodically cleaning content and showing new one when needed. I think it is also common approach, nothing special. Problem is I want to add loading indicator to my page and found good one - Acr.UserDialogs. Starting and hiding indicator is very easy... but. Damn problem is timing is wrong. Suppose I have some page on screen with some controls, texts etc. when user hits back button I show loading indicator, clear page, display new content and hide loading indicator. But what happens in reality - function that displays new content ends successfully and hides loading indicator - that happens almost momentarily - no new content displayed yet, no page changes and loading indicator is already off. Is there any way to catch moment when new content really is displayed on page? I've tried to check visibility of one of elements (stack layout) isvisible and isenabled, but those damn things simply do not work - they are misleading. Any other ways?

See What’s New in Visual Studio 2017 Version 15.5

$
0
0

Today we released Visual Studio 2017 version 15.5 into stable! Read the blog post here for more information and feel free to discuss below!

Mac App rejected due to MapKit not being linked

$
0
0

My app was rejected from the Mac App Store for the following reason:
2.3 - Apps that do not perform as advertised by the developer will be rejected

The app still has the MapKit entitlement without linking against the MapKit framework.

My application targets the 64 bit architecture, links to the Native MapKit, associates the CFBundleIdentifier in Info.plist to the one created with Apple with Maps permissions. I am using the latest Stable releases of Xamarin.

Any thoughts on why this would happen?

Publishing an app in to the playstore

$
0
0

Can anyone help me on this Which one is better to distribute the android app using adhoc or Google play??

Thanks in advance.

Color properties in storyboard doesn't work properly.

$
0
0

Hi all, I'm using Visual Studio 2017 and developing an application for IOS devices. I have two buttons that has different background color property on the view. When I selected one of them, property window always show that the background color is red. I'm changing that property but when I selected the other one the background color property stays as the previous one. Is there a way to solve this?

Versions for Mac and PC:
On Mac: Visual Studio Community 7.3(build 799), Xamarin.IOS 11.6.1.2
On PC: Visual Studio Community 15.5.1, Xamarin.IOS 11.6.1.2

Binding Objective C Lib

$
0
0

I developed an application which wants to bind with Objective c lib (.a file). This application has lots of packages which supports Target framework Xamarin Mac Full. But when I created the binding project it is created as Xamarin Mac Modern. When I changed it to Xamarin Mac Full it shows lots of error, Xamarin.Mac reference is also missing. Please help me on this. How to solve this issue. I am new in Xamarin, so please excuse if anything wrong.


Importing NSPerformService

$
0
0

I've tried to import NSPerformService and got this so far:
[System.Runtime.InteropServices.DllImport("System/Library/Frameworks/AppKit.framework/Versions/C/AppKit")]<br /> static extern bool NSPerformService(string item, NSPasteboard pboard);

Unfortunately, when I call it I get System.Runtime.InteropServices.MarshalDirectiveException:

Type AppKit.NSPasteboard which is passed to unmanaged code must have a StructLayout attribute.

I realize that it is something about marshaling, so that probably NSPasteboard should be sent like IntPtr or something else, but I have no idea on how to do that (this thread contains the solution when this happens on the return value, but it can't be applied when the problem is in the argument: https://forums.xamarin.com/discussion/57248/type-foundation-nsdictionary-which-is-passed-to-unmanaged-code-must-have-a-structlayout-attribute).

I guess the answer would help to other people that might have similar problem in the future as there aren't too many threads regarding this and definitely not about this specific issue.

XamarainShellPackage did not load correctly in VS 2015

$
0
0

Hello,
I try to use Xamarin with VS 2015, but even after several uninstall/install/repair of Xamaribn and Visual Studio, when I launch VS 2015 the following message appears: "The 'XamarinShellPackage' did not load correctly". (See 'ActivityLog.xml' attached.)

That is the first error message, second message appears when I want to create a new solution based on Xamarin, it cannot create the iOS and Android projects and display the following message : "A problem was encountered creating the sub project 'xxx.iOS'. Required service 'EnvDTE.DTE' not found.

Can you please help resolve that problem ?

Thank you in advance

J-D Gasser

Mac Certificates - Not able to sign the app with Developer ID application certificate

$
0
0

We are planning to distribute our MAC app out of app store. We face some problem in signing the app.
We created Developer ID application and developer ID Distribution certificates. We have given these certificates in MAC signing options. Here we have checked ‘Sign the application Bundle’ and given the identity as Developer ID Application and selected the correct Provisioning profile. Then we have selected the ‘Sign Installer Package’ option and given the Developer ID installer. We are getting a dialog (Provisioning Profile) with a message 'No Valid Provisioning Profile Found' when we click on Sign and Distribute button while archive and Publishing.

We are able to sign with Mac App Distribution certificate. But we are not able to sign with Developer ID Application and Developer ID installer certificates (For outside app store) . Please help us to resolve this issue.

VS Mac Ios Scrollview

$
0
0

I can do the hard stuff but this agrevating me. Get an Ios app view to scroll. I have a sample solution from another forum member , it builds and runs in the sim fine. I cant get my stupid hello world scroll to move. Simp single view using the Storybook. Have the controller, it is set for freeform and the view is extended. added the a scrollview from tool box added views and button. It builds show the top of the view but wont scroll down. What am i missing???? information is vague or deprecated. Thanx for reading and any feedback.

This project type requires Xamarin.Android to be installed help!

$
0
0

After updating, this error appeared

This project type requires Xamarin.Android to be installed help!

Viewing all 204402 articles
Browse latest View live


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