Modify Scpreferences Persistent Storage: Invalid Argument

Is it possible to unpair a Bluetooth device in Cocoa/ObjC?

Paired devices are a part of System Preferences.

You can find the file with the bluetooth preferences in /Library/Preferences, its name is com.apple.Bluetooth.plist.

com.apple.Bluetooth.plist

However, you cannot edit the file directly. You should use SCPreferences class from System Configuration framework.

Note the API for accessing/modifying system preferences is pretty low level.

EDIT: The following code works if run in superuser mode. I am not a Mac OS developer myself but it should be possible to init it with an AuthorizationRef and run it with user mode (the user will confirm access to system configuration).

SCPreferencesRef prefs = SCPreferencesCreate(kCFAllocatorDefault,
CFSTR("Test"),
CFSTR("/Library/Preferences/com.apple.Bluetooth.plist"));

const CFStringRef PAIRED_DEVICES_KEY = CFSTR("PairedDevices");

NSArray *pairedDevices = (__bridge NSArray *) SCPreferencesGetValue(prefs, PAIRED_DEVICES_KEY);

NSLog(@"Paired devices: %@", pairedDevices);

NSString *deviceToRemove = @"e4-32-cb-da-ca-2f";

NSMutableArray *newPairedDevices = [pairedDevices mutableCopy];
[newPairedDevices removeObject:deviceToRemove];

Boolean valueSet = SCPreferencesSetValue(prefs, PAIRED_DEVICES_KEY, (__bridge CFPropertyListRef) [NSArray arrayWithArray:newPairedDevices]);

NSLog(@"Value set: %@", (valueSet) ? @"YES" : @"NO");

if (!valueSet) {
NSLog(@"Error: %@", SCCopyLastError());
}

Boolean saved = SCPreferencesCommitChanges(prefs);

if (!saved) {
NSLog(@"Error: %@", SCCopyLastError());
}

NSLog(@"Saved: %@", (saved) ? @"YES" : @"NO");

CFRelease(prefs);

invalid argument creating a ruby dev env with docker & fig

TL;DR

Turned the computer off and then on again.

Resolved.

Persistent Storage using Application.Current.Properties not working

I have had a ton of problems with Application.Current.Properties on Android. I highly suggest using Xamarin Settings plugin instead which I have never had any issues with. It is persistent even when the app is closed.

That being said Application.Current.Properties is supposed to work even when you close the app. Not sure why it wouldn't but it does not surprise me either.

*Edit: To use once it is installed, basically CrossSettings.Current is the plugin class that will do the work but the example just creates a separate property to access it. So create a new file, lets call it SettingsImplementation:

public static class SettingsImplementation {

#region Instance

private static Lazy<ISettings> _appSettings;

public static ISettings AppSettings {
get {
if(_appSettings == null) {
_appSettings = new Lazy<ISettings>(() => CrossSettings.Current, LazyThreadSafetyMode.PublicationOnly);
}

return _appSettings.Value;
}
set {
_appSettings = new Lazy<ISettings>(() => value, LazyThreadSafetyMode.PublicationOnly);
}
}

#endregion

private const string UserNameKey = "username_key"; //Key used to get your property
private static readonly string UserNameDefault = string.Empty; //Default value for your property if the key-value pair has not been created yet

public static string UserName {
get { return AppSettings.GetValueOrDefault<string>(UserNameKey, UserNameDefault); }
set { AppSettings.AddOrUpdateValue<string>(UserNameKey, value); }
}
}

Then to use that you would do this anywhere in your app:

SettingsImplementation.UserName = "something";

OR

string username = SettingsImplementation.UserName;

How to access Flutter's shared preference file?

I found a work-around, by directly modify the files in Android virtual machine:
Go to Android View -> Tool Windows -> device file explorer.

Here you will see all the files on the virtual phone device.

Navigate to your app folder, normally in data/data/com.example.yourprojectname

In shared_prefs folder, there is an XML file containing all the local key-value pairs, you can directly modify it, or delete it here.

PS: At the current stage, if the Flutter app has heavy features based on local (SQLite and shared preference), Android Studio is a much better-developing tool than VSCode, for much better virtual device inspection.

Error on Tomcat Embedded startup

I finally found the solution to my issue.

Reading the anwer to this question: How to disable Tomact session persistence in Spring Boot via Manager pathname? (suggested by AntJavaDev) I configured this bean:

@Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
tomcat.addContextCustomizers(new TomcatContextCustomizer() {

@Override
public void customize(Context context) {
if (context.getManager() instanceof StandardManager) {
// print local path name
System.out.println(((StandardManager) context.getManager()).getPathname());
}
}
});
return tomcat;
}

This way I discovered where cached sessions are stored for Tomcat Embedded (on Windows):

C:\Users\<my-user>\AppData\Local\Temp\<random-id>\servlet-sessions\

I deleted the SESSIONS.ser file in this folder and the error is magically disappeared.



Related Topics



Leave a reply



Submit