Custom URL Scheme maximum URL length Custom URL Scheme maximum URL length ios ios

Custom URL Scheme maximum URL length

Unfortunately, the answer does not seem to be available. The max len is not defined specifically in any iOS documentation that I could find.

There are limits, as noted above by MSK's link, for the URL base url length, not the absolute string length of the url. So thats probably a safe bet for a max, around 2000 characters.

However, in testing there seemed to be no upper limit. I was able to use 365,535 character URLs on iOS with no problems. But there is no requirement for apple to continue to support it, so it's a "use at your own risk". I would however, say that based on the fact that many, many apps are using this to transfer information, including large amounts of data between apps, that Apple will probably continue to support it, since there seems to be no reason to reduce the length.

(The following is a repost from another question's answer, but it directly answers the question here as well.)

On Apple platforms (iOS/iPadOS/macOS/tvOS/watchOS), the limit is a 2 GB long URL scheme, as seen by this comment in the source code of Swift:

// Make sure the URL string isn't too long.// We're limiting it to 2GB for backwards compatibility with 32-bit executables using NS/CFURLif ( (urlStringLength > 0) && (urlStringLength <= INT_MAX) ){...

On iOS, I've tested and confirmed that even a 300+ MB long URL is accepted. You can try such a long URL like this in Objective-C:

NSString *path = [@"a:" stringByPaddingToLength:314572800 withString:@"a" startingAtIndex:0];NSString *js = [NSString stringWithFormat:@"window.location.href = \"%@\";", path];[self.webView stringByEvaluatingJavaScriptFromString:js];

And catch if it succeed with:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{    NSLog(@"length: %@", @(request.URL.absoluteString.length));    return YES;}

The answers above are misleading. The docs don't really mention it but paths and file names do have length limits.

You can see here there is a limit to the length a file path or name can take up. You can check these in syslimits.h.

#define NAME_MAX          255   /* max bytes in a file name */#define PATH_MAX         1024   /* max bytes in pathname */

You can log them and see for yourself like so:


Paths are limited at 1024 bytes or 1024 characters in UTF-8.Filenames in paths are limited to 255 bytes or 255 characters in UTF-8.

I ran into this problem trying to deal with files that have encoded Japanese characters (which lengthen the URL/names significantly). My only solution is to crop the name as of right now.

You can see here on this apple support page that they talk about how some languages (like korean or japanese) have characters that take up more bytes and cause problems (they don't really provide a good way to deal with the problem though):