Closed jfversluis closed 1 year ago
Issue moved from dotnet/maui#14857
From @msftbot[bot] on Monday, May 1, 2023 8:42:47 AM
Hi @s3743761. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md
This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
Issue moved from dotnet/maui#14857
From @drasticactions on Monday, May 1, 2023 8:43:37 AM
I recommend trying what you're doing in a dotnet iOS app (dotnet new ios
) to see if it works there.
Issue moved from dotnet/maui#14857
From @s3743761 on Monday, May 1, 2023 8:59:22 AM
@drasticactions no It still doesn't work. This is my code
[Register ("AppDelegate")]
public class AppDelegate : UIApplicationDelegate {
public override UIWindow? Window {
get;
set;
}
public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
{
// create a new window instance based on the screen size
Window = new UIWindow (UIScreen.MainScreen.Bounds);
// create a UIViewController with a single UILabel
var vc = new UIViewController ();
vc.View!.AddSubview (new UILabel (Window!.Frame) {
BackgroundColor = UIColor.SystemBackground,
TextAlignment = UITextAlignment.Center,
Text = "Hello, iOS!",
AutoresizingMask = UIViewAutoresizing.All,
});
Window.RootViewController = vc;
// make the window visible
Window.MakeKeyAndVisible ();
NSNotificationCenter.DefaultCenter.AddObserver(
NSUserDefaults.DidChangeNotification,
DefaultsChanged,
null);
GetStringValue("key1");
return true;
}
private void DefaultsChanged(NSNotification notification)
{
// Get the user defaults
Console.WriteLine("DefaultsChanged");
}
public const string MangedConfigurationKey = "com.apple.configuration.managed";
public string GetStringValue(string key)
{
var dic = NSUserDefaults.StandardUserDefaults.DictionaryForKey(MangedConfigurationKey);
if (dic != null)
{
NSObject value = null;
if (dic.TryGetValue(new NSString(key), out value) && value != null)
Console.WriteLine(value.ToString());
}
return null;
}
}
GetStringValue works, but not the notification
According to Apple's documentation:
This notification isn't posted when changes are made outside the current process
So it looks like this is behaving as designed.
Issue moved from dotnet/maui#14857
From @s3743761 on Monday, May 1, 2023 8:25:21 AM
Description
iOS api NSUserDefaults.DidChangeNotification doesn't get invoked when UserDefaults get changed. This is required for MDM implementation in iOS using AppConfig
Steps to Reproduce
and create a method as in same class
xcrun simctl spawn booted defaults write {apple_bundle_id} com.apple.configuration.managed -dict 'key1' 'VALUE1'
.xcrun simctl spawn booted defaults delete {apple_bundle_id}
Ideally, the Console.WriteLine("Notified"); should be triggered with the command from step 5.
Link to public reproduction project repository
given in description
Version with bug
7.0 (current)
Last version that worked well
Unknown/Other
Affected platforms
iOS
Affected platform versions
iOS 16 and before
Did you find any workaround?
No response
Relevant log output
No response