Code to check the RTMP and Non- RTMP url? - ios

NSURL *url = [[NSURL alloc] initWithString:#"https://www.rmp-streaming.com/media///bbb-360p.mp4"];
NSURL *URL =[[NSURL alloc]initWithString:#"https://www.youtube.com/watch?v=zQRvYYoV6bc"];
I have two URLs. I want to frame a condition to check whether the provided URL is RTMP URL OR not.

You can check by using NSURL hostname,
NSURL *url = [[NSURL alloc] initWithString:#"https://www.rmp-streaming.com/media///bbb-360p.mp4"];
url.host will return www.rmp-streaming.com
for this url,
NSURL *URL =[[NSURL alloc]initWithString:#"https://www.youtube.com/watch?v=zQRvYYoV6bc"];
url.host will return www.youtube.com
Now you can decide what you want. Code not tested, this is just suggestion.

Related

NSString to NSURL returns false

I have a URL which is in a string: http://bs.serving-sys.com/BurstingPipe/adServer.bs?cn=is&c=23&pl=VAST&pli=10226041&PluID=0&pos=6670&ord=%5B1423164382.84%5D&cim=1
I am trying to convert that string to NSURL.
I've tried several things, which are:
NSString *encodedString = [#"http://bs.serving-sys.com/BurstingPipe/adServer.bs?cn=is&c=23&pl=VAST&pli=10226041&PluID=0&pos=6670&ord=%5B1423164382.84%5D&cim=1" stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSURL *url = [NSURL URLWithString:encodedString];
When I follow the URL object with a breakpoint it assigns 0 => false.
What should I do to convert that string to NSURL?
The parameters in your given URL string are already URL encoded. So:
NSString *string = #"http://bs.serving-sys.com/BurstingPipe/adServer.bs?cn=is&c=23&pl=VAST&pli=10226041&PluID=0&pos=6670&ord=%5B1423164382.84%5D&cim=1";
NSURL *url = [NSURL URLWithString:string];
// url is not nil

How to decode NSURL in iOS?

i am NewBie in iOS Development. I want to Decode my NSURL With Pagination Here my Url Like as
http://www.janvajevu.com/webservice/categorylist.php?category=%E0%AA%B8%E0%AB%8D%E0%AA%B5%E0%AA%BE%E0%AA%B8%E0%AB%8D%E0%AA%A5%E0%AA%AF&page=0
And i Decode this URL Like as
NSURL *urls = [NSURL URLWithString:#"http://www.janvajevu.com/webservice/categorylist.php?category=%E0%AA%B8%E0%AB%8D%E0%AA%B5%E0%AA%BE%E0%AA%B8%E0%AB%8D%E0%AA%A5%E0%AA%AF&page=0"];
NSString *urlString = [urls absoluteString];
NSLog(#"UrlString %#",urlString);
NSURL * url=[NSURL URLWithString:urlString];
But it Give me Only 0 Page Url i want to Like as make my url as
NSURL *urls=[NSURL URLWithString:#"My Url &page=%d",pagenum];
Here i want at place of My Url as Decoding of my Original Url If it is Possible then Please Give me Solution for it.
you are doing it in wrong way.
this is the right way
NSString *urlString = #"http://www.janvajevu.com/webservice/categorylist.php?category=%E0%AA%B8%E0%AB%8D%E0%AA%B5%E0%AA%BE%E0%AA%B8%E0%AB%8D%E0%AA%A5%E0%AA%AF&page=";
NSURL *targetURL = [NSURL URLWithString:[NSString stringWithFormat:#"%#%d",urlString,pageNumber]];
NSLog(#"targetURL is : %#",targetURL);
Hope this will help you..
NSString *str=#"http://www.janvajevu.com/webservice/categorylist.php?category=%E0%AA%B8%E0%AB%8D%E0%AA%B5%E0%AA%BE%E0%AA%B8%E0%AB%8D%E0%AA%A5%E0%AA%AF&page=0";
NSString *result =[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *urls = [NSURL URLWithString:result] ;

NSURL always nil [duplicate]

I want to parse the location of my Documents Directory to NSUrl from NSString I have.
when my console NSLog(stringURL)
i get: "/var/mobile/Applications/2B35D06D-6E4A-40F2-833E-28463A946834/Library/Application Support/MyAppDirectory" as an output.
but when I do
NSURL* url = [NSURL URLWithString:stringUrl];
and NSLog(url) i get (null) as an output.
WHat am I doing wrong here?
From the apple documentation "An NSURL object initialized with URLString. If the URL string was malformed or nil, returns nil." Your stringURL isn't a correct formed url. For reference: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/Reference/Reference.html#//apple_ref/occ/clm/NSURL/URLWithString:
What you actually want to use is: fileURLWithPath: isDirectory: instead.
NSURL *url = [NSURL fileURLWithString:[stringURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] isDirectory:YES];
NSLog(#"%#", url);
How about:
NSURL* url = [NSURL fileURLWithString:stringUrl];
// ^^^^
Use fileURLWithPath instead (since you are passing a file path):
NSURL* url = [NSURL fileURLWithPath:stringUrl];

Using baseurl in UIWebView

I have some issues loading a site that apparently has to do with needing to properly set a baseurl. The main site is http://www.oklahomachristianacademy.org and the site address I need to have open is a string that returns as
applewebdata://F6224B10-25ED...
So, in my code I thought this would work to set the baseurl and the string attached above to load into the app.
-(void)viewWillAppear:(BOOL)animated {
NSURL *theurl = [NSURL URLWithString:#"http://www.oklahomachristianacademy.org/"];
[savedweb loadHTMLString:(NSString *)link baseURL:(NSURL *)theurl];
}
However, this does not work, and the UIWebview simply displays the applewebdata:// line again. What am I missing?
use this code
//NSString *urlAddress = #"http://www.google.com";
NSString *urlAddress = #"http://cagt.bu.edu/page/IPhone-summer2010-wiki_problemsandsolutions";
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webView loadRequest:requestObj];

NSURL - Set modify path

I need to use a NSURL object to reach different ressources on the same host.
Here is what I do:
#define MY_HOST #"my.server.eu"
NSURL *url = [[NSURL alloc] initWithScheme:#"http" host:MY_HOST path:#"/"];
Now I need to deal with
http://my.server.eu/path1
http://my.server.eu/path2
http://my.server.eu/path3
How can I modify the path of my NSURL object ?
Why can't we simply do url.path = #"path1" ?
How can I modify the path of my NSURL object ?
Why can't we simply do url.path = #"path1" ?
Because NSURL is an immutable object, and you can't change its properties afterwards. NSMutableURL does not exist, but is on the wish list of many.
In order to achieve what you're after, you're going to have to make 3 separate NSURL objects I'm afraid. To do so, you can convenience the paths within an array:
NSString *host = #"http://my.server.eu/";
NSArray *paths = #[#"path1", #"path2", #"path3"];
NSURL *path1 = [NSURL URLWithString:[NSString stringWithFormat:#"%#%#", host, path[0]]];
NSURL *path2 = [NSURL URLWithString:[NSString stringWithFormat:#"%#%#", host, path[1]]];
NSURL *path3 = [NSURL URLWithString:[NSString stringWithFormat:#"%#%#", host, path[2]]];
You should make the base URL as you're doing and then build the others relative to it using +[NSURL URLWithString:relativeToURL:].

Resources