Closed myers-gh1328 closed 1 year ago
Are you sure it's supported?
Hi @mmyers299. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. 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.
@drasticactions I am 100% sure, it is specifically mentioned in Apple's documentation (see last item in screenshot). There is also a button in the simulator device menu (and a shortcut) to "shake" the device.
The simulator supports the "Shake" gesture, which is not the same thing as the accelerometer.
The implementation in Essentials uses CMMotionManager
which, correctly, says that the accelerometer is not available, because it's not. So the way MAUI detects shakes will not work with the simulator.
That said, there are other ways to detect it within .NET and iOS, but getting to it from MAUI UI is tricky.
[Register("AppDelegate")]
public class AppDelegate : MauiUIApplicationDelegate
{
public AppDelegate()
{
}
protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp();
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
application.ApplicationSupportsShakeToEdit = true;
return base.FinishedLaunching(application, launchOptions);
}
}
The shake gesture requires setting "ApplicationSupportsShakeToEdit" on the UIApplication, which you can get to from the AppDelegate.
However, the subscribe to the events, you need to override the underlying UIApplication or UIViewControllers for the Motion events. They are not event handlers, but methods that are called that you would override... which you can only, AFAIK, do in MAUI if you create your own UIViewController and somehow wire it into the existing stack... which seems not viable.
@rolfbjarne Is what I'm saying correct? Is there anything this person can do?
However, the subscribe to the events, you need to override the underlying UIApplication or UIViewControllers for the Motion events. They are not event handlers, but methods that are called that you would override... which you can only, AFAIK, do in MAUI if you create your own UIViewController and somehow wire it into the existing stack... which seems not viable.
@rolfbjarne Is what I'm saying correct? Is there anything this person can do?
I'm not sure what you can and can't do in MAUI, but your explanation of how it has to be implemented seems to be correct as far as I can tell.
Closing this issue as it is not supported using the MAUI shake detection. However, if this is a feature that is important to you, please open a new issue for a new feature request so that we can track that and discuss the implementation.
Description
The iOS simulator is throwing a Microsoft.Maui.ApplicationModel.FeatureNotSupportedException when I try to use the accelerometer to detect the shake event. I followed the below article which does not mention anything about this not being available for the iOS simulators. And according to Apple's documentation this is a supported feature. https://help.apple.com/simulator/mac/current/#/devb0244142d
https://learn.microsoft.com/en-us/dotnet/maui/platform-integration/device/sensors?view=net-maui-7.0&tabs=ios#shake
Steps to Reproduce
Link to public reproduction project repository
https://github.com/mmyers299/maui-sensor-bug
Version with bug
7.0 (current)
Last version that worked well
Unknown/Other
Affected platforms
iOS
Affected platform versions
All
Did you find any workaround?
Comment out the code only when debugging on an iOS simulator
Relevant log output
No response