Skip to content

Add a strongly typed SRSensorReader.RequestAuthorization overload #18464

@rolfbjarne

Description

@rolfbjarne

See customer struggle here:

https://discord.com/channels/732297728826277939/732297808148824115/1120406222974234685

They were doing this:

var sensors = new NSString[] {
    new NSString(SRSensor.MessagesUsageReport.ToString()),
    new NSString(SRSensor.PhoneUsageReport.ToString()),
    new NSString(SRSensor.DeviceUsageReport.ToString())
};
var nsset = new NSSet<NSString>(sensors);
await SRSensorReader.RequestAuthorizationAsync(nsset);

when the correct is this:

var sensors = new NSString[] {
    new NSString(SRSensor.MessagesUsageReport.GetConstant()),
    new NSString(SRSensor.PhoneUsageReport.GetConstant()),
    new NSString(SRSensor.DeviceUsageReport.GetConstant())
};
var nsset = new NSSet<NSString>(sensors);
await SRSensorReader.RequestAuthorizationAsync(nsset);

However, we should be able to improve the API to something like this:

var sensors = new [] {
    SRSensor.MessagesUsageReport,
    SRSensor.PhoneUsageReport,
    SRSensor.DeviceUsageReport,
};
await SRSensorReader.RequestAuthorization (sensors);

and then we just do the right thing in this overload, making it impossible for customers to make this kind of mistake again.

Just to clarify, we should add a manual overload taking an array of SRSensor values:

void RequestAuthorization (SRSensor[] sensors, Action<NSError> completion);

Even better if there was a way to make the async overload take a params array:

Task RequestAuthorizationAsync (params SRSensor[] sensors);

and then the calling code becomes:

await SRSensorReader.RequestAuthorization (
    SRSensor.MessagesUsageReport,
    SRSensor.PhoneUsageReport,
    SRSensor.DeviceUsageReport);

Metadata

Metadata

Assignees

No one assigned

    Labels

    copilot-candidateenhancementThe issue or pull request is an enhancementgood first issueThis is a good first issue for someone to start working with our codehelp wantedThis is an issue or pull request where we request help from the community to fix or complete

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions