Skip to content

feat(ios): Support custom scheme event for iOS#1112

Merged
GitToTheHub merged 5 commits into
apache:masterfrom
kumo01GitHub:feat/customurlscheme-ios
Feb 10, 2026
Merged

feat(ios): Support custom scheme event for iOS#1112
GitToTheHub merged 5 commits into
apache:masterfrom
kumo01GitHub:feat/customurlscheme-ios

Conversation

@kumo01GitHub

Copy link
Copy Markdown
Contributor

Platforms affected

iOS

Motivation and Context

Implements CB-14187, which adds support for the AllowedSchemes preference and customscheme event for iOS. #274 is same context and I referred but the PR is not updated for years.

Description

Add support for the AllowedSchemes preference and customscheme event for iOS.

Testing

Tested with iOS simulator.

Checklist

  • I've run the tests to see all new and existing tests pass
  • I added automated test coverage as appropriate for this change
  • Commit is prefixed with (platform) if this change only applies to one platform (e.g. (android))
  • If this Pull Request resolves an issue, I linked to the issue in the text above (and used the correct keyword to close issues using keywords)
  • I've updated the documentation if necessary

@GitToTheHub

Copy link
Copy Markdown
Contributor

This replicates #274 for the WKWebView

Comment thread src/ios/CDVWKInAppBrowser.m Outdated
return NO;
}

- (BOOL)isAllowedScheme:(NSString*)scheme

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep the code formatting, there should be a space between the type and pointer asterisk:

- (BOOL)isAllowedScheme:(NSString *)scheme

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed it following the other lines.

Comment thread src/ios/CDVWKInAppBrowser.m Outdated

- (BOOL)isAllowedScheme:(NSString*)scheme
{
NSString* allowedSchemesPreference = [self.commandDelegate.settings objectForKey:@"AllowedSchemes"];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep the formatting:

NSString *allowedSchemesPreference

Use the _settings property to get a setting:

[_settings cordovaSettingForKey:@"AllowedSchemes"]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed it following the other lines.

Comment thread src/ios/CDVWKInAppBrowser.m Outdated
// Preference missing.
return NO;
}
for (NSString* allowedScheme in [allowedSchemesPreference componentsSeparatedByString:@","]) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep the formatting:

NSString *allowedScheme

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed it following the other lines.

Comment thread src/ios/CDVWKInAppBrowser.m Outdated
[theWebView stopLoading];
[self openInSystem:url];
shouldStart = NO;
} else if ((self.callbackId != nil) && ![[ url scheme] isEqualToString:@"http"] && ![[ url scheme] isEqualToString:@"https"] && [self isAllowedScheme:[url scheme]]) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • You don't need braces for (self.callbackId != nil) just write self.callbackId != nil
  • scheme is a property of url, write url.scheme instead of [ url scheme]
  • Add documentation to the condition, what's happening here

@kumo01GitHub kumo01GitHub Feb 9, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Add documentation to the condition, what's happening here

I added comment and clarify the condition.

} else if ((self.callbackId != nil) && ![[ url scheme] isEqualToString:@"http"] && ![[ url scheme] isEqualToString:@"https"] && [self isAllowedScheme:[url scheme]]) {
// Send a customscheme event.
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsDictionary:@{@"type":@"customscheme", @"url":[url absoluteString]}];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • absoluteString is a property of url, write url.absoluteString instead of [url absoluteString]

// Send a customscheme event.
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsDictionary:@{@"type":@"customscheme", @"url":[url absoluteString]}];
[pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Write here pluginResult.keepCallback = [NSNumber numberWithBool:YES];

Comment thread src/ios/CDVWKInAppBrowser.m Outdated
return NO;
}

- (BOOL)isAllowedScheme:(NSString*)scheme

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document this method

@kumo01GitHub

kumo01GitHub commented Feb 9, 2026

Copy link
Copy Markdown
Contributor Author

@GitToTheHub
Thank you for your review. The comments you pointed out primarily concern code formatting, and I determined that most of them should be corrected.
However, considering the overall structure, making these corrections would also change the formatting of other lines. Therefore, if proceeding with the corrections, consistency must be ensured across the entire codebase. And it is out of this PR's purpose.

I have a few suggestions.:

  • Only correct obvious errors and make another PR to fix the others.
  • Fix all of them only in InAppBrowser.m.

@kumo01GitHub

kumo01GitHub commented Feb 9, 2026

Copy link
Copy Markdown
Contributor Author

Only correct obvious errors and make another PR to fix the others.

I think above choice is better so that I fixed following this policy for now.

@GitToTheHub

Copy link
Copy Markdown
Contributor

Can you make up to date with the master?

@kumo01GitHub kumo01GitHub force-pushed the feat/customurlscheme-ios branch from ac7b046 to da984b0 Compare February 9, 2026 15:55
@kumo01GitHub kumo01GitHub force-pushed the feat/customurlscheme-ios branch from da984b0 to 80b38ed Compare February 9, 2026 16:05
@kumo01GitHub

kumo01GitHub commented Feb 9, 2026

Copy link
Copy Markdown
Contributor Author

Can you make up to date with the master?

I updated my branch.

@kumo01GitHub

Copy link
Copy Markdown
Contributor Author

@GitToTheHub
I got the build error reason. The _settings is a property of CDVWKInAppBrowserViewController but I defined isAllowedScheme as private method of CDVWKInAppBrowser. It's my trivial mistake...

I think the point is who should check scheme. I think CDVWKInAppBrowser should do as other schemes. So that I restored it.

@GitToTheHub

Copy link
Copy Markdown
Contributor

You are right, _settings is a property of CDVWKInAppBrowserViewController and isAllowedScheme a method CDVWKInAppBrowser. Looks good now.

@GitToTheHub GitToTheHub merged commit 03831d7 into apache:master Feb 10, 2026
@kumo01GitHub kumo01GitHub deleted the feat/customurlscheme-ios branch February 10, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants