There's a C function, `urlEncode`, defined in INKHandler that does this. You should be using that instead of manually doing it.
(e.g. https://github.com/intentkit/IntentKit/blob/master/IntentKit/Handlers/INKMapsHandler.m#L31)