iPhone App to listen radio - iphone

I'd like to create an iPhone App that allows people to listen to radio. Below is what I've done so far, but when I click on the button nothing happen, can someone please advise what I've done wrong here.
Thanks in advance.
#import <UIKit/UIKit.h>
#interface RadioViewController : UIViewController{
IBOutlet UIWebView *webView;
}
-(IBAction)radio;
#property(nonatomic,retain)UIWebView *webview;
#end
#import "RadioViewController.h"
#import <MediaPlayer/MediaPlayer.h>
#implementation RadioViewController
#synthesize webview;
-(IBAction)radio{
NSURL *url = [NSURL URLWithString:#"http://db5195728.tis.core.005.cdn.streamfarm.net:80/3212_erf_96_live.mp3"];
NSURLRequest *req = [NSURLRequest requestWithURL: url];
[webview loadRequest:req];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end

I've tried your code. It works fine here. So:
Make sure your radio is called when you tap that button. You can set a break point there or add a NSLog to see whether it is called;
Make sure your webview is correctly add to your view:shown and of the correct size.

Related

Load Webview in different view in iOS Programming

I have been programming an Web browser app for iOS and stumbled upon an issue. At first my search text field and web view where in the same view (Everything was fine :). When I put the web view in an different view the web view wouldn't load up the page and stay blank. So the issue is the web view will not load in a different view (will work if text field and web view are in the same view).
My Code:
#import "ViewController.h"
#import <QuartzCore/QuartzCore.h>
#interface ViewController ()
#end
#implementation ViewController
#synthesize searchButton;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib
}
-(IBAction)SearchButton:(id)sender {
NSString *query = [searchField.text stringByReplacingOccurrencesOfString:#" " withString:#"+"];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"http://www.google.com/search?q=%#", query]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
ViewController *WebView = [self.storyboard instantiateViewControllerWithIdentifier:#"WebView"];
[self presentViewController:WebView animated:YES completion:nil];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.view endEditing:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
The SearchButton method refers to a webView in the current class, but it's the new ViewController (you call it WebView) which is about to be presented and that should contain a UIWebView. So the UIWebView on the presented view controller is never getting to loadRequest.
Create a subclass of UIViewController to contain your web view. (call it something like MyWebViewController) It should have a property called urlString. Make sure to change the class of the view controller you currently have painted in storyboard to MyWebViewController.
The SearchButton method should look like this:
// renamed to follow convention
- (IBAction)pressedSearchButton:(id)sender {
NSString *query = [searchField.text stringByReplacingOccurrencesOfString:#" " withString:#"+"];
NSString *urlString = [NSString stringWithFormat:#"http://www.google.com/search?q=%#", query];
// remember to change the view controller class in storyboard
MyWebViewController *webViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"WebView"];
// urlString is a public property on MyWebViewController
webViewController.urlString = urlString;
[self presentViewController:webViewController animated:YES completion:nil];
}
The new class can form the request from the urlString...
// MyWebViewController.h
#property (nonatomic, strong) NSString *urlString;
#property (nonatomic, weak) IBOutlet UIWebView *webView; // be sure to attach in storyboard
// MyWebViewController.m
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSURL *url = [NSURL URLWithString:self.urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];
}

UIWebView autosize issue only on iOS 4.3

I am trying to figure out how to fix this bug that only occurs on iOS 4.3. When the application launches, it displays a PDF that is scaled to fit in the UIWebView. It behaves perfectly until you pinch to zoom on the document, and then rotate it, leaving behind a black area. If you don't pinch to zoom, it doesn't leave the black area. I don't understand why this is a iOS 4.3 only issue.
Screenshot of the issue: I've been trying to solve this problem awhile now, and would greatly appreciate your help. Thank you.
Screenshots of the .xib settings:
The code I'm using is:
.h:
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
{
UIWebView *webView;
}
#property (nonatomic) IBOutlet UIWebView *webView;
#end
.m:
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize webView;
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
return YES;
} else {
return (interfaceOrientation !=
UIInterfaceOrientationPortraitUpsideDown);
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *urlAddress = [[NSBundle mainBundle] pathForResource:#"test" ofType:#"pdf"];
NSURL *url = [NSURL fileURLWithPath:urlAddress]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#end
I recall there being a few bugs with UIWebView and rotation in the past. I remember specifically that there were some rendering and resizing issues. In all honesty, if it has worked since iOS 4.3 then I think you shouldn't even bother trying to fix the issue -- in all likelihood the fix you will come up with will be hacky and irrelevant at this point.
That being said, this thread might help you solve the problem.
If it works in iOS6, it may because the shouldAutorotateToInterfaceOrientation is never be called in it. The way to handle rotation is changed in iOS6. It happened to work in your code.
Another possible solution is to use delegate of webview to wait untill it's loaded then add it to the view.

Passing variables to the view from AppDelegate

i open a view in AppDelegate
with:
AppDelegate
PushDetail *pushdtls = [[PushDetail alloc] initWithNibName:nil bundle:nil];
pushdtls.seminarurl = [NSURL URLWithString:resourcePathURL]; /passing URL
[self.window presentModalViewController:pushdtls animated:YES];
PushDetail.h
#property (nonatomic) NSURL *seminarurl;
PushDetail.m
- (void)viewDidLoad
{
NSURLRequest *requestObj = [NSURLRequest requestWithURL:seminarurl];
[pushDetails loadRequest:requestObj];
}
But the webview is empty... what I do wrong?
and the second question how to close the view I opened?
- (IBAction) closeNews{
//[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
//[self release];
[self dismissModalViewControllerAnimated:YES];
}
does not work :(
You may implement the UIWebViewDelegate protocol within your view controller and fetch the results/error messages yourself.
Namely didFailLoadWithError - see the UIWebViewDelegate Protocol References for more.
Maybe its just a typo on your URL.
Example:
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
NSLog(#"oops, failed with error: %#", error);
}
You've not specified what pushDetails is, but I'm assuming it's an IBOutlet to a UIWebview on your PushDetail controller. My guess is that you've forgotten to bind your pushDetails outlet to the webview in your nib file.
You could create lets say a file that holds all your global variables lets call it GlobalVariables.h and .m. In the GlobalVariables.h file add this
extern NSURL *seminarurl;
#interface GlobalVariables
#property (retain, nonatomic) NSURL *seminarurl;
#end
and in the GlobalVariables.m file add
#import "GlobalVariables.h"
#implements GlobalVariables
#synthesize seminarurl;
NSURL *seminarurl; // You could add what your URL is here as well you would just use '='
#end
So when you want to access it or assign a variable to it, it would just be like accessing or assigning any other variable. Just remember to import 'GlobalVariables.h' into which ever .m file you are using it in.
make your property retained. ex >> #property (nonatomic,retain).
if the url is a property in your app delegate .. you can access it like this
[UIApplication SharedApplication].delegate.yourpropertyname;

Open Link in UIWebView in Safari

I am working on an app that receives a feed that I display in a UIWebView. The feed has embedded links that I want to open in Safari instead of thew WebView. I have looked over several other questions that are posted here. I am not sure what I am missing, but I think it is something simple. Here are my .h and .m files
#import
#class BlogRss;
#interface EnduranceDailyWorkoutViewController : UIViewController {
IBOutlet UIWebView * descriptionTextView;
BlogRss * currentlySelectedBlogItem;
}
#property (nonatomic, retain) UIWebView * descriptionTextView;
#property (readwrite, retain) BlogRss * currentlySelectedBlogItem;
#end
#import "EnduranceDailyWorkoutViewController.h"
#import "BlogRss.h"
#implementation EnduranceDailyWorkoutViewController
#synthesize descriptionTextView = descriptionTextView;
#synthesize currentlySelectedBlogItem = currentlySelectedBlogItem;
- (void)viewDidLoad {
[super viewDidLoad];
NSString *html = [NSString stringWithFormat:#"%# %#",currentlySelectedBlogItem.title, currentlySelectedBlogItem.contentEncoded];
[descriptionTextView loadHTMLString:html baseURL:[NSURL URLWithString:nil]];
}
-(BOOL)webView:(UIWebView *)descriptionTextView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if (UIWebViewNavigationTypeLinkClicked == navigationType) {
[[UIApplication sharedApplication] openURL:[request URL]];
return NO;
}
return YES;
}
Using Interface Builder I have linked the IBOutlet and the UIWebView. Please let me know what I am missing. I have put break points in the webView section but the code never hits there so it is almost like something is not linked correctly in IB.
You need to ensure that the UIWebView's delegate is set to your controller. You can do this in interface builder, or you can modify your viewDidLoad method:
- (void)viewDidLoad {
[super viewDidLoad];
// add this line to set the delegate of the UIWebView
descriptionTextView.delegate = self;
NSString *html = [NSString stringWithFormat:#"%# %#",currentlySelectedBlogItem.title, currentlySelectedBlogItem.contentEncoded];
[descriptionTextView loadHTMLString:html baseURL:[NSURL URLWithString:nil]];
}

I can't get UIWebViewDelegate to work

I'm trying to implement a UIWebViewDelegate in my application and I cannot for the life of me get it to work. I would really appreciate a second set of eyes on this.
I know the name MapViewController is confusing, but the WebView is controlling a map (not UIMapView).
Here's the bulk of the code:
MapViewController.h
#import <UIKit/UIKit.h>
#import <UIKit/UIWebView.h>
#interface MapViewController : UIViewController<UIWebViewDelegate> {
IBOutlet UIWebView *webView;
}
#property (nonatomic, retain) IBOutlet UIWebView *webView;
#end
MapViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
webView.delegate = self;
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"map" ofType:#"html"]isDirectory:NO]];
[webView loadRequest:request];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
NSLog(#"Done loading.");
}
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
NSLog(#"hi");
return NO;
}
- (void)dealloc {
webView.delegate = nil;
[webView release]
[super dealloc];
}
Thanks for any help!
Does the initial page you're loading actually display? Are you sure you connected your webview in Interface Builder?
go interface builder , connect the delegate to the file's owner , then it should work.
Open Interface Builder
Right click on the Web View object
Drag the delegate onto files owner.
Things to check:
if map.html is in the bundle. Put it on the root of the bundle, not on resources.
if it is, right click on it, and choose get info. Verify on TARGETS if the target is checked for the file.
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
NSLog(#"hi");
return YES; // for all supported oreintation.
}