András Tóth‘s professional blog
banditoth.net

Hey there 👋, I’m banditoth a .NET MAUI developer from Hungary.
I write about software development with .NET technologies.

You can find me on:
LinkedIn | Github | StackOverflow | X / Twitter | Threads

Tag: xamarin ios

  • Xamarin.Forms: ‘MSBuild:UpdateDesignTimeXaml’ code generator crashed solution

    This content has 3 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

    If you are facing an issue after updating the Xamarin.Forms version in your project, with the following error:

    SOMEXAMLFILE.xaml: Error: The 'MSBuild:UpdateDesignTimeXaml' code generator crashed: Not connected
      at MonoDevelop.Core.Execution.RemoteProcessConnection.PostMessage (MonoDevelop.Core.Execution.BinaryMessage message, System.Threading.Tasks.TaskCompletionSource`1[TResult] cs, System.Boolean checkInitialized) [0x000c3] in /Users/builder/azdo/_work/2/s/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Execution/RemoteProcessConnection.cs:438 
      at MonoDevelop.Core.Execution.RemoteProcessConnection.SendMessage (MonoDevelop.Core.Execution.BinaryMessage message) [0x00031] in /Users/builder/azdo/_work/2/s/main/src/core/MonoDevelop.Core/MonoDevelop.Core.Execution/RemoteProcessConnection.cs:385 
      at MonoDevelop.Projects.MSBuild.RemoteBuildEngineManager+<>c__DisplayClass20_0.<GetBuildEngine>b__5 () [0x00252] in /Users/builder/azdo/_work/2/s/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/RemoteBuildEngineManager.cs:323 
      at MonoDevelop.Projects.MSBuild.RemoteBuildEngineManager.GetBuildEngine (MonoDevelop.Core.Assemblies.TargetRuntime runtime, System.String minToolsVersion, System.String solutionFile, System.String group, System.Object buildSessionId, System.Boolean setBusy, System.Boolean allowBusy) [0x0036f] in /Users/builder/azdo/_work/2/s/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/RemoteBuildEngineManager.cs:273 
      at MonoDevelop.Projects.MSBuild.RemoteBuildEngineManager.GetRemoteProjectBuilder (System.String projectFile, System.String solutionFile, MonoDevelop.Core.Assemblies.TargetRuntime runtime, System.String minToolsVersion, System.Object buildSessionId, System.Boolean setBusy, System.Boolean allowBusy) [0x000df] in /Users/builder/azdo/_work/2/s/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/RemoteBuildEngineManager.cs:176 [...]
    

    Then clean your solution, and restart Visual Studio for Mac.

  • Xamarin iOS: UIWebView Deprecation megoldása

    This content has 5 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

    Április 30-tól az AppStore-ba nem tölthetjük fel az UIWebView implementációt tartalmazó binárisainkat. Erről korábban írtam már a blogon, hogy miért problémás, a Xamarin fejlesztésnél ez a történet.

    Amennyiben sikerült felimádkoznunk a legfrissebb csomagokat a Solutionre, abban az esetben az iOS projekt mtouch argumentumai közé a következőt kell beállítanunk:

    --optimize=experimental-xforms-product-type 
    

    Figyelni kell rá, hogy ahol CustomWebViewRenderer-t használunk, ott az ősosztály ne WebViewRenderer legyen, hanem WKWebViewRenderer.

    Ezen felül a linking-nél a linker behaviourt vagy Link all, vagy Link Framework SDK-s only-ra kell állítani.

  • Xamarin iOS: Nem reagál az alkalmazás az értintésekre

    This content has 5 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

    Konzolban a hibaüzenet található, de az alkalmazás hiba nélkül kifordul, de az iOS 13.4.1-es verziót futtató eszközökön az érintések nem működnek.

    Hiba a konzolban:

    2020-04-12 15:25:09.177 PROJNAME.iOS[521:71276] <_UISystemGestureGateGestureRecognizer: 0x283c60b00>: Touch: Failed to receive system gesture state notification before next touch
    2020-04-12 15:25:09.177 PROJNAME.iOS[521:71276] <_UISystemGestureGateGestureRecognizer: 0x283c60900>: Gesture: Failed to receive system gesture state notification before next touch
    
    

    Megoldás: Visual Studio for Mac 8.5.1-es verzióról (vagy ennél kisebb verzióról) fel kell frissíteni a MacVS-t, a Windowsos verzójában a hiba a 16.5.2-től lett orvosolva.

    https://github.com/xamarin/Xamarin.Forms/issues/10162

  • Xamarin iOS: FirebaseMessaging NuGet frissítés

    This content has 5 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

    Hibajelenség: Az alkalmazás lefordul, és deployolódik az iOS-t futtató telefonra, de az indítás után azonnal bezárul, és a debugger nem veszi ezt észre.

    Hibaüzenet az OutputWindow-ban

    dyld: symbol '_OBJC_CLASS_$_GULUserDefaults' not found, expected in '/private/var/containers/Bundle/Application/ID/APPLICATIONNAME/Frameworks/GoogleUtilities.framework/GoogleUtilities', needed by '/private/var/containers/Bundle/Application/ID/APPLICATIONNAME/Frameworks/FirebaseMessaging.framework/FirebaseMessaging'
    
    

    Clean solution nem oldja meg a problémát.

    Nálam a bin és az obj mappák manuális törlése megoldotta a problémát a DEBUG buildhez, de akinek továbbra is problémája adódik ezzel az próbálja ki a következő módszereket:
    https://stackoverflow.com/questions/57131541/issue-with-nuget-package-xamarin-firebase-ios-cloudmessaging-3-1-2

    Azonban Release módban ugyanúgy nem működik az alkalmazás.

  • Xamarin Forms / iOS: Backspace detektálás Entryben

    This content has 5 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

    Androidtól eltérően, iOS-en az EntryRenderer nem rendelkezik overrideolható DispatchKeyEventtel. Viszont magának a UITextFieldnek van egy DeleteBackward metódusa, ami a visszatörlés esetén hívódik meg. Ahhoz, hogy ezt felüldefiniáljuk, örököltetnünk kell egy UITextField-et.

    public class UITextFieldWithExtendedFuncionallity : UITextField
    {
        public delegate void DeleteBackwardEventHandler(object sender, EventArgs e);
    
        public event DeleteBackwardEventHandler OnDeleteBackward;
    
    
        public void OnDeleteBackwardPressed()
        {
            if (OnDeleteBackward != null)
            {
                OnDeleteBackward(this, new EventArgs());
            }
        }
    
        public UITextFieldWithExtendedFuncionallity()
        {
    
        }
    
        public override void DeleteBackward()
        {
            base.DeleteBackward();
            OnDeleteBackwardPressed();
        }
    }
    

    Mivel ez egy natív Custom UserControl, ahelyett, ahogy StackOverFlow-n, és egyéb helyeken ajánlják, nem az EntryRenderer-ben fogjuk beállítani natív kontrolként. StackOverflow-on, és Xamarin Fórumon CTRL+C, CTRL-V kód működik jól, de nem tekinthető szép megoldásnak. Ezeken a helyeken azt ajánlják, hogy az EntryRenderer OnElementChanged metódusában hozzunk létre egy új példányt az általunk örököltetett natív usercontrolból, majd állítsuk be azt natív kontrolként. Ilyenkor létrejön feleslegesen egy UITextField, és mi is létrehozunk egy UITextField gyereket, és az előzőleg létrejött field feleslegesen került a memóriában lefoglalásra, feleslegesen fordított a készülék erőforrásokat a konstruktorok és egyéb inicializáló függvények és procedúrák megfuttatására.

    Emiatt, létre kell hoznunk a natív egyedi usercontrolunkhoz egy Renderert a következőképp:

    [assembly: ExportRenderer (typeof(Entry), typeof(UITextFieldWithExtendedFuncionallityRenderer))]  
    namespace DemoApp.iOS.CustomControlRenderers
    {
        public class UITextFieldWithExtendedFuncionallityRenderer : ViewRenderer<Entry, UITextFieldWithExtendedFuncionallity>
        {
            private UITextFieldWithExtendedFuncionallity nativeControl;
    
            protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
            {
                base.OnElementChanged(e);
                var model = e.NewElement;
    
                if (model == null)
                {
                    return;
                }
    
                nativeControl = new UITextFieldWithExtendedFuncionallity();
    
                SetNativeControl(nativeControl);
            }
        }
    }
    

    Majd a Xamarin Forms Custom UserControl rendererjének ősét át kell állítani EntryRendererről az imént létrehozott rendererre.

    public class NakedEntryRenderer : UITextFieldWithExtendedFuncionallityRenderer
    

    Az Forms U.C. Elementchangedjében már elérhetőek a fent definiált delegatek.

    protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
            {
                base.OnElementChanged(e);
    
                if (Control != null)
                {
                    if(Control is UITextFieldWithExtendedFuncionallity nativeControl)
                    {
                        nativeControl.OnDeleteBackward += NativeControl_OnDeleteBackward;
                    }
                }
            }
    
            private void NativeControl_OnDeleteBackward(object sender, EventArgs e)
            {
                if(Element is CustomEntry formsEntry)
                {
                    formsEntry.OnBackspacePressed();
                }
            }
    

    A Forms-os UserControl-ban található BackspacePressed event az Androidos mintára épül.

    public class CustomEntry: Entry
    {
        public delegate void BackspaceEventHandler(object sender, EventArgs e);
     
        public event BackspaceEventHandler OnBackspace;
     
        public CustomEntry() { }
     
        public void OnBackspacePressed() 
        {
            if (OnBackspace != null)
            {
                OnBackspace(null, null);
            }
        }
    }