Skip to content

How to access enum values and provide a completionHandler? (Request iOS local notification permission) #33

@loftafi

Description

@loftafi

I have been exploring if I can use zig-objc to replace my clunky swift side build. I first checked to see if there was sample code that might demonstrate the intent for how we would access enum values (to create an NSUInteger) and how to provide a completionHandler

    // UNUserNotificationCenter *un = [UNUserNotificationCenter currentNotificationCenter];
    const un = objc.getClass("UNUserNotificationCenter").?;
    const cnc = un.msgSend(objc.Object, "currentNotificationCenter", .{});

    // https://developer.apple.com/documentation/usernotifications/unauthorizationoptions
    // UNAuthorizationOptions options = UNAuthorizationOptionAlert +
    //     UNAuthorizationOptionSound +
    //     UNAuthorizationOptionBadge;
    const options = objc.enum??.UNAuthorizationOptions??? //enum UNAuthorizationOptions : NSUInteger;

    //[un requestAuthorizationWithOptions:(UNAuthorizationOptions) options 
    //    completionHandler:(void (^)(BOOL granted, NSError *error)) completionHandler];
    cnc.msgSend(objc.Object, "requestAuthorizationWithOptions", .{
        options,
        completionHandler, // Can this be just a function?
    });
}

Any input would be greatly appreciated.

PS: By way of feedback, I wonder if we could get an /examples folder for zig-objc to demonstrate some more advanced basic patterns like this. Thanks for your work on this cool zig project.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions