xcode run a url without uiwebview - objective-c

How to run a URL in Xcode objective-c without using uiwebview
I try this code but its not work
UIWebView *webView = [[UIWebView alloc]init];
[webView loadRequest:[NSURLRequest requestWithURL:myURL]];
the url like this:
#"http://www...com/library/ws_setLike.php?book_ID=%#&user_ID=%#",bookID,userID];

For non https urls you must allow arbitrary loads in NSAppTransportSecurity:
NSURLSession/NSURLConnection HTTP load failed on iOS 9

I think this should do the trick: (This is of course on the assumption that if you do not want to use a UIWebView you will want to use the default browser on the device)
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: #"http://www...com/library/ws_setLike.php?book_ID=%#&user_ID=%#",bookID,userID]];

Related

UIDocumentInteractionController not transferring to target application

My app is generating an image which I'm attempting to pass to Instagram using a document interaction controller and their hook. Oh, this is using iOS 5.1.
I have the UIDocumentInteraction action sheet showing up properly but the issue is that once the user select "open in Instagram" the sheet is dismissed and nothing happens.
The code:
// Method returns a path to the generated image
NSURL *finalCompositePath = [NSURL fileURLWithPath:[self generateFinalImage:#"instagram"]];
UIDocumentInteractionController *documentInteractionController;
NSURL *instagramURL = [NSURL URLWithString:#"instagram://camera"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
//imageToUpload is a file path with .ig file extension
documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:finalCompositePath];
documentInteractionController.UTI = #"com.instagram.exclusivegram";
documentInteractionController.delegate = self;
documentInteractionController.annotation = [NSDictionary dictionaryWithObject:#"Caption Test" forKey:#"InstagramCaption"];
[documentInteractionController presentOptionsMenuFromBarButtonItem:self.ShareButton animated:YES];
}
Thoughts?
UIDocumentsInteractionController shows iBooks but doesn't open it has the correct answer for apps using arc. UIDocumentInteractionController must be a property of the class.
BUT ALSO!!!
If you are supporting down to ios5, make sure the image you've saved is a type ".igo" (not .jpg or .png).
IOS6 will open it up in instagram, but IOS less than 6 will just dismiss the UIDocumentInteractionController without proceeding to instagram.

iOS, openURL opens odd webpage... (welcome to appe.com)

When user click the link,
it should go to the app store page(angry bird page).
this is the code:
NSString *url = #"http://itunes.apple.com/us/album/angry-birds-rio-samba-single/id426982849?uo=4";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
but, first time when I click the link, it goes to odd webpage.
(blank white page with text "welcome to appe.com", not apple.com).
and when when I click the link again, it goes to the right page.
anyone who experience with this situation?
this is error page on app store.
It's strange. Ia haven't experienced such situation yet. However, the link you are trying to open is not the Angry birds Rio GAME, but a SONG. If you want to lead user to Angry birds Rio game in app store, you should rather use:
NSString* urlString=#"itms-apps://itunes.apple.com/pl/app/angry-birds-rio/id420635506?mt=8";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
(the protocol is not http:// but itms-apps://
use this link instead
NSString *url = #"http://itunes.apple.com/us/album/angry-birds-rio-samba-single/id426982849?ign-mpt=uo%3D4";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
I double-checked the url. and that was the problem.
I use this url,
http://itunes.apple.com/us/album/angry-birds-rio-samba-single/id426982849
not this correct one,
http://itunes.apple.com/us/album/angry-birds-rio-samba-single/id426982849?uo=4
I modified the url and it fixed the problem.

Launch Facebook page with scheme?

In my app I have a button. Pressing the button takes me to the Facebook app with the scheme: fb://. But I want to have a scheme to link to my facebook page. fb://page/MYPAGENAME doesn't work or am I doing it wrong? Help is much appreciated!
Edit
This is what the method looks like now:
- (IBAction)facebookButton:(id)sender
{
NSURL *url = [NSURL URLWithString:#"fb://MYPAGENAME"];
[[UIApplication sharedApplication] openURL:url];
}
I've added a username to my page now.

Calling UIWebView from IBAction ButtonPressed

This is probably a simple question...
I have a UIView with a button that corresponds to a URL address http:// etc. I want to be able to click this web address button and have it load a UIWebView on a separate UIViewController and XIB that shows the website, allowing me to then hit a back button and go back to my first view that has the original button. Basically I want to be able to load the webpage but have it operate within the App rather than start up Safari. Is this possible?
So far I have build a dedicated XIB and ViewController for my webpage for which the viewDidLoad method looks like this:
- (void)viewDidLoad{
[super viewDidLoad];
NSString *urlAddress = pushURL; //pushURL is passed as parameter
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObject = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObject];
[addressBar setText:urlAddress];
}
Question is... how do I call the UIWebView from my button (which is in the first class/parent viewController)? All my other viewControllers in my app are using UITableView so it's a simple DidSelectRowAtIndex.
Thanks.
It sounds like you want to be using a UINavigationController. Then when the button is tapped just push the UIViewController with the web view to the UINavigationController.

How to open web browser with UIWebView

Hey guys,
On my Xcode project, I am trying to open a web browser at the click of one of my buttons, but here's what I'm really trying to do. First of all, I am opening a web browser using this example code:
NSURL *fanPageURL = [NSURL URLWithString:#"fb://profile/210227459693"];
if (![[UIApplication sharedApplication] openURL: fanPageURL]) {
NSURL *webURL = [NSURL URLWithString:#"http://www.facebook.com/pages/Blackout-Labs/210227459693"];
[[UIApplication sharedApplication] openURL: webURL];
}
[super viewDidLoad];
Now this code works properly, but the problem is that it's closing my application and opens the link in the Safari application, which is not what I want. I went the other way around by creating another view (after click the button), then inserted a UIWebView using Interface Builder, but it still didn't work. So I was hoping someone can help me out how to open this link within my app instead of closing my app and opening the link in the Safari app, thanks
Look at SVWebViewController. It's a ready made UIViewController subclass with a UIWebView in it and all you need to do to show it is
SVWebViewController *webViewController = [[SVWebViewController alloc] initWithAddress:#"http://google.com"];
[self.navigationController pushViewController:webViewController animated:YES];
There is also a modal version, see the Usage Section.
You'll need to create a UIViewController subclass that has UIWebView as a subview, and show that when the button in tapped.