25

Friends i have simple audio player (MPMoviePlayerController) which can play audio stream. On iOS 11 i have very interessing trouble, thousand time i have error and my stream was stopped:

NSURLConnection finished with error - code -1002

I paste this code (this code i saw on stackowerflow) but it's not help to me:

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
        <key>NSExceptionDomains</key>
        <dict>
            <key>cast.mysite.com</key>
            <dict>
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <true/>
                <key>NSIncludesSubdomains</key>
                <true/>
            </dict>
        </dict>
    </dict>

Maybe you know best solution?

Genevios
  • 1,115
  • 1
  • 16
  • 29

3 Answers3

38

That error should not be related to using HTTP instead of HTTPS. App Transport Security failures return error code -1022.

The error code -1002 indicates an invalid URL. Perhaps your HTTP live streaming playlist file contains a structurally invalid URL (e.g. missing scheme, a scheme other than http/https, etc.)?

For additional debugging, set this environment variable

CFNETWORK_DIAGNOSTICS=1

in your Xcode project and re-run the app. Once you know what URL is failing, the problem will likely become more obvious.

If it isn't, file a bug.

dgatwood
  • 10,129
  • 1
  • 28
  • 49
1

This issue can appear if your URL contains spaces. I solved it by replacing the spaces with "%20", and then you can use it safely. The Objective C code to replace the spaces is below.

your_url_variable_name = [your_url_variable_name stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
  • No, my URL don't have no one space. Like this site.com/blabla.json – Genevios Dec 07 '19 at 12:55
  • Any illegal character should cause the NSURL to be nil, so if you can create an NSURL from it successfully, it shouldn't be an illegal character issue, and if you can't, well then there's your problem. :) – dgatwood May 29 '20 at 19:13
-2

First thing you must use secure server (server with valid certificate). I'm not sure either it is necessary or not because i never tried to hit server with invalid certificate. You can try this code (not sure it will work for you or not) put this code in Appdelegate.m

@implementation NSURLRequest(DataController)
+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host
{
    return YES;
}
@end
Zeeshan Arif
  • 509
  • 5
  • 15
  • 1
    I will try this after 2-3 days and answer, if it's ok i will accept your answer, but anyway thanks! – Genevios Oct 12 '17 at 11:23
  • 7
    This is a very, very bad idea. This disables all URL request security for your entire app, and your app will be rejected from the iOS App Store if you try it. – dgatwood Nov 28 '17 at 17:56