davidortinau / Xappy

A mobile app to track Xamarin news and explore all the goodness that is .NET for Mobile developers
MIT License
350 stars 106 forks source link

Cannot run in iOS simulator #55

Open sandman202 opened 4 years ago

sandman202 commented 4 years ago

Code builds fine. When I run in simulator mode, it gives.

System.Exception: Error adding record: MissingEntitlement at Xamarin.Essentials.KeyChain.SetValueForKey (System.String value, System.String key, System.String service) [0x0009a] in D:\a\1\s\Xamarin.Essentials\SecureStorage\SecureStorage.ios.tvos.watchos.cs:126 at Xamarin.Essentials.SecureStorage.SetAsync (System.String key, System.String value, Security.SecAccessible accessible) [0x00027] in D:\a\1\s\Xamarin.Essentials\SecureStorage\SecureStorage.ios.tvos.watchos.cs:24 at Xamarin.Essentials.SecureStorage.PlatformSetAsync (System.String key, System.String data) [0x00000] in D:\a\1\s\Xamarin.Essentials\SecureStorage\SecureStorage.ios.tvos.watchos.cs:38 at Xamarin.Essentials.SecureStorage.SetAsync (System.String key, System.String value) [0x00021] in D:\a\1\s\Xamarin.Essentials\SecureStorage\SecureStorage.shared.cs:27 at Xappy.Domain.Global.AppModel.set_UseDarkMode (System.Boolean value) [0x00001] in /Users/g7kw3/tmp/Xappy-master/Xappy/Xappy/Domain/Global/AppModel.cs:79 at Xappy.Domain.Global.AppModel.InitAsync () [0x0009f] in /Users/g7kw3/tmp/Xappy-master/Xappy/Xappy/Domain/Global/AppModel.cs:23 at AsyncAwaitBestPractices.SafeFireAndForgetExtensions.HandleSafeFireAndForget[TException] (System.Threading.Tasks.Task task, System.Boolean continueOnCapturedContext, System.Action`1[T] onException) [0x00027] in /Users/bramin/GitHub/AsyncAwaitBestPractices/Src/AsyncAwaitBestPractices/SafeFireAndForgetExtensions.cs:61 at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__7_0 (System.Object state) [0x00000] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/external/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1021 at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.4.0.2/src/Xamarin.iOS/Foundation/NSAction.cs:178

navkar commented 4 years ago

I am seeing the same error as well. Not sure why it doesnt run on iOS

AndyDentFree commented 4 years ago

The solution is in the forum here Set the iOS project's Custom Entitlements to your Entitlements.plist

iOS project => Properties => iOS Bundle Signing

Screen Shot 2019-11-18 at 11 36 46 am
tampham1210 commented 4 years ago

@AndyDentFree I tried but it still not working

jamesmontemagno commented 4 years ago

@davidortinau it may be worth doing a check not to use secure settings on the simulator with the DeviceInfo.DeviceType and just not store data as you are on a simulator :)

navkar commented 4 years ago

Just remove the existing entries in Entitlements.plist and yours. its working after that.

kgouraw commented 4 years ago

@navkar and @davidortinau removing "Entitlements.plist" is just solving compilation error but getting the same runtime error on iPhone Simulator what @sandman202 has reported.

AndyDentFree commented 4 years ago

As a general comment, the Xamarin toolchain seems to be back to needing frequent nuking - other problems I've had with SkiaSharp were fixed by carefully removing all bin and obj directories.

Apple have done things with XCode11 that also seem to have made accounts more fragile - I had to ensure my account details were correct in XCode11 before I could get auto-signing working for devices.

AndyDentFree commented 4 years ago

I just reviewed my changes and confirmed that this also works when compiling and running the simulators on Catalina (originally was on older Mac). I'm using XCode 11.2.1 and Visual Studio Mac 8.3.10

I have made two changes. (apologies for not taking time to do a PR - have multiple deadlines within the week)

in Xappy.iOS.csproj after the MTouchDebug element

    <CodesignProvision>iOS Team Provisioning Profile: *</CodesignProvision>
    <CodesignKey>iPhone Developer</CodesignKey>
    <CodesignEntitlements>Entitlements.plist</CodesignEntitlements>

in Xappy.ios/Renderers/PageRenderer.cs fixed a startup crash due to previousTraitCollection being null

        public override void TraitCollectionDidChange(UITraitCollection previousTraitCollection)
        {
            base.TraitCollectionDidChange(previousTraitCollection);
            var hadPrevCollection = previousTraitCollection != null;
            Console.WriteLine(hadPrevCollection ?
                $"TraitCollectionDidChange: {TraitCollection.UserInterfaceStyle} != {previousTraitCollection.UserInterfaceStyle}" :
                $"TraitCollectionDidChange: {TraitCollection.UserInterfaceStyle} != null prior collection"
            );

            if (!hadPrevCollection || this.TraitCollection.UserInterfaceStyle != previousTraitCollection.UserInterfaceStyle)
            {
                SetAppTheme();
            }            
        }
Lazareena commented 3 years ago

Removing the Entitlement.plist and commenting out the references to SecureStorage in the AppModel.cs file worked for me. The downside is the UseDarkMode setting will not be saved on the simulator

julpanid commented 3 years ago
  1. Add Custom Entitlements image

  2. Add new key to Entitlements.plist <key>keychain-access-groups</key> <array> <string>$(AppIdentifierPrefix)com.microsoft.adalcache</string> </array>

this solution working well for me.