Changing tel: property working in simulator but Not in Device - iphone

I have changed tel property to do some string manipulation instead of calling that number.
its working in simulator but when i do it device, its still trying to call.
i have tried with webview, textview, button still same problem :(
Any idea?
Let me rephrase
By default, when clicked on any link with tel:xxxx iPhone calls number xxxx
But i don't want calling, instead i want to grab xxxx and append that value to my String.
How to do that.
Thanks
- (void)viewDidLoad {
[super viewDidLoad];
self.htmlString = [self createHTML];
[webView setBackgroundColor:[UIColor clearColor]];
[webView setOpaque:NO];
[webView loadHTMLString:self.htmlString baseURL:nil];
}
- (NSMutableString *) createHTML {
NSMutableString *tempString =[NSMutableString stringWithFormat:#"<div>"];
[tempString appendString:#"John Smith"];
[tempString appendFormat:#"<br> <a href='tel:201207415'>201207415</a>"];
[tempString appendString:#"</div>"];
return tempString;
}
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
//CAPTURE USER LINK-CLICK.
NSURL *url = [request URL];
NSString *mytext = [url absoluteString];
NSLog(#"%#",mytext);
myLabel.text = mytext;
return YES;
}

If you do not want to call:
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
return NO;
}
Simulator cannot call anyway.

Related

ios - How to append javascript with HTML content?

I'm trying to get access token,I'm following this link to get that,but some condition fails,I think am not properly append the javascript with HTML content.
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
if(_data)
{
NSString* content = [[NSString alloc] initWithData:_data
encoding:NSUTF8StringEncoding];
[_data release];
_data = nil;
NSString *jsString = #"<script type='text/javascript'>\
window.external =\
{\
'Notify': function(s) { document.location = 'acs://settoken?token=' + s; },\
'notify': function(s) { document.location = 'acs://settoken?token=' + s; }\
}\
</script>";
content = [jsString stringByAppendingString:content];
[webView loadHTMLString:content baseURL:_url];
}
}
- (BOOL)webView:(UIWebView *)webView
shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType
{
if(_url)
{
if([_url isEqual:[request URL]])
{
return YES;
}
[_url release];
}
//Here am getting http://LoginSuccess.aspx
_url = [[request URL] retain];
NSString* scheme = [_url scheme];//Here am getting http
//So here condition fails
if([scheme isEqualToString:#"acs"])
{
// parse the JSON URL parameter into a dictionary
_url = [NSURL URLWithString:#"https://converse.accesscontrol.windows"];
NSDictionary* pairs = [self parsePairs:[_url absoluteString]];
if(pairs)
{
WACloudAccessToken* accessToken;
accessToken = [[WACloudAccessToken alloc] initWithDictionary:pairs];
//[WACloudAccessControlClient settoken:accessToken];
[self dismissModalViewControllerAnimated:YES];
}
return NO;
}
[NSURLConnection connectionWithRequest:request delegate:self];
return NO;
}
Any ideas? Thanks in advance.
I´m not sure if i unterstand exactly what you´re trying to do, but I assume
[UIWebView stringByEvaluatingJavaScriptFromString:#"yourJavaString"];
could help. I use it to perform an JavaScript based Loginmechanism in one of my projects.
See the Apple doc here .
You have to use stringByEvaluatingJavaScriptFromString AFTER WebView has loaded.

Webview content is not readable after stop animating loading image

I am building one iPhone application where I have two views one for login view and another for web view. When user enters the login credentials, then it will redirect to web view. while loading the webview from login view too much time is taking to load. hence I used alertview to show loading image.
#interface FocusViewController ()
#end
#implementation FocusViewController
#synthesize txtsecurecode;
#synthesize webView;
#synthesize OrganizationCode;
UIActivityIndicatorView *indicator;
UIAlertView *alert;
- (void)viewDidLoad
{
[super viewDidLoad];
appDelegate = (FocusAppDelegate *)[[UIApplication sharedApplication]delegate];
if(appDelegate.data.strOrganizationCode == nil || appDelegate.data.strAccessCode == nil)
{
NSLog(#"YOUR FIRST SCREEN");
_loginView.hidden = NO;
webView.hidden = YES;
}
else
{
NSLog(#"LOAD WEBVIEW DIRECTLY\n");
NSLog(#"Organization Code -> %# \n Secure Access Code -> %#",appDelegate.data.strOrganizationCode,appDelegate.data.strAccessCode);
OrganizationCode.text = appDelegate.data.strOrganizationCode ;
txtsecurecode.text = appDelegate.data.strAccessCode;
[self loginClicked:nil];
webView.hidden = NO;
_loginView.hidden = YES;
}
}
- (IBAction)loginClicked:(id)sender {
#try {
if([[txtsecurecode text] isEqualToString:#""] || [[OrganizationCode text] isEqualToString:#""] ) {
[self alertStatus:#"Please enter Access code" :#"Login Failed!":0];
}
else
{
NSString *post =[[NSString alloc] initWithFormat:#"txtsecurecode=%# #&password=%#",[txtsecurecode text],[OrganizationCode text]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"http://myexample.com/AccountService/security/ValidateAccess?accesscode=%#&companycode=%#&type=1", txtsecurecode.text, OrganizationCode.text]];
NSString *responseData = [[NSString alloc]initWithData:[NSData dataWithContentsOfURL:url] encoding:NSUTF8StringEncoding];
if([responseData isEqualToString:#""]){
[self alertStatus:#"Please enter valid Access Code" :#"Login Failed !" :0];
}
else
{
appDelegate.data.strOrganizationCode = OrganizationCode.text;
appDelegate.data.strAccessCode = txtsecurecode.text;
[FocusAppDelegate addCustomObjectToUserDefaults:appDelegate.data key:kCredentails];
//Updated
_loginView.hidden = YES;
webView.hidden = NO;
responseData = [responseData stringByReplacingOccurrencesOfString:#" "" " withString:#""];
NSString* encodedString = [responseData stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(#"Response ==> %#" ,encodedString);
alert = [[[UIAlertView alloc] initWithTitle:#"Loading\nPlease Wait..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
[alert show];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50);
[indicator startAnimating];
[alert addSubview:indicator];
[indicator release];
webView.backgroundColor = [UIColor clearColor];
webView.opaque = NO;
webView.delegate = self;
webView.frame = self.view.bounds;
NSString* urlTwo = [[encodedString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
stringByReplacingOccurrencesOfString:#"%22" withString:#""];
NSURL *url2;
if([urlTwo hasPrefix:#"http://"]){
url2 = [NSURL URLWithString:urlTwo];
}else{
url2 = [NSURL URLWithString:[NSString stringWithFormat:#"http://%#" , urlTwo]];
}
NSLog(#"url2:%#", url2);
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url2];
[webView loadRequest:requestObj];
[[self view] addSubview:webView];
}
}
}
#catch (NSException * e) {
NSLog(#"Exception: %#", e);
[self alertStatus:#"Login Failed." :#"Login Failed!" :0];
}
}
-(void)webViewDidStartLoad:(UIWebView *)webView{
NSLog(#"webViewDidStartLoad");
[self.view addSubview:self.indicator];
alert.hidden = NO;
}
- (void) webViewDidFinishLoad:(UIWebView *)webView {
NSLog(#"webViewDidFinishLoad");
[self.indicator removeFromSuperview];
[self.alert dismissWithClickedButtonIndex:1 animated:NO] ;
}
- (IBAction)backgroundClick:(id)sender
{
[txtsecurecode resignFirstResponder];
[OrganizationCode resignFirstResponder];
}
#end
Until content in webview displays, loading image is displaying and working good. but content of webview is not editable and remaining static as I think I used 'web view.hidden = YES'. when I comment the alert method and run then content of webview is also editable and working good as required. I need to load the content of url after loading image stops loading.
I would suggest show the activity indicator from the Viewcontroller having the WebView and implement the WebView Delegate methods
- (void)webViewDidStartLoad:(UIWebView *)webView
{
[actvityIndicator startAnimating];
}
and
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[actvityIndicator stopAnimating];
}
this will keep your webview Interactive and also show the indicator till the page loads completely
you can try something like this. The Delegate is important in .h file
FocusViewController.h
#interface FocusViewController : UIViewController <UIWebViewDelegate> {
UIActivityIndicatorView *indicator;
}
FocusViewController.m
- (void)viewDidLoad
{
// Loading Indicator
indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[indicator setColor:[UIColor colorWithRed:50.0/255.0 green:120.0/255.0 blue:200.0/255.0 alpha:1.0]];
}
- (void)webViewDidStartLoad:(UIWebView *)webView
{
[indicator startAnimating];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[indicator stopAnimating];
}

How to Download a video using UIWebView

I want to download a the video using web-view but I am not getting how to download it?
my video link is here
the sample code for playing video which I am using is
-(void)embedYouTubeInWebView:(NSString*)url theWebView:(UIWebView *)aWebView {
   NSString* html = [NSString stringWithFormat:#"%#", url];
   [aWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:html]]];
}
- (void)viewDidLoad
{
   [super viewDidLoad];
   
  [self embedYouTubeInWebView:#"http://player.vimeo.com/video/32983838" theWebView:myWebView];
   // Do any additional setup after loading the view, typically from a nib.
}
can anyone please help me to download this video?
To download a file i used the following Code. Hope it will work for you too.
- (IBAction)getFileFromFtpServer:(UIView *)sender
{
NSString *stringURL = #"http://player.vimeo.com/video/32983838";
NSURL *url = [NSURL URLWithString:stringURL];
NSData *urlData = [NSData dataWithContentsOfURL:url];
if ( urlData )
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:#"%#/%#", documentsDirectory,#"filename.mpeg4"];
[urlData writeToFile:filePath atomically:YES];
}
}
Try this here your video is playing..
- (void)viewDidLoad
{
[super viewDidLoad];
UIWebView* webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 380)];
webView.delegate=self;
[webView setOpaque:NO];
webView.backgroundColor=[UIColor clearColor];
CGRect screen = [[UIScreen mainScreen] bounds];
CGFloat width = CGRectGetWidth(screen);
CGFloat height = CGRectGetHeight(screen);
UIActivityIndicatorView * activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
activityIndicator.frame=CGRectMake((width/2) - 10,(height/2) - 54, 20, 20);
activityIndicator.center=self.view.center;
[activityIndicator hidesWhenStopped];
[self playVideo];
}
-(void) playVideo
{
NSURL *url = [NSURL URLWithString:#"http://player.vimeo.com/video/32983838"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[self.webView loadRequest:request];
[activityIndicator startAnimating];
[webView addSubview:activityIndicator];
}
/* WebViewDidStartLoad */
- (void)webViewDidStartLoad:(UIWebView *)webView
{
[activityIndicator startAnimating];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
}
/* WebViewDidFinishLoad */
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[activityIndicator stopAnimating];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}
/* WebViewdidFailLoadWithError */
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
}
If I understand correctly and in response to above, google has shut down several "converter sites" due to copyright infringements: http://www.real.com/resources/youtube-to-mp3-converter There are other sites available to download video content from (again, assuming you're abiding by the copyright guidelines) : This lists five sites where you can find and download online videos free. To make sure a video is legal to download, look for licensing information about the video. Typically, videos with a “Creative Commons” license are legal to download, but may have limitations on how you use the video. http://www.real.com/resources/download-one-video

Why UIWebView work so slowly when loadHTMLString with UIWebView?

It take about 10s to loadHTMLString in my APP, who can point out what's the problem?
- (void)viewDidLoad {
[super viewDidLoad];
webView = [[UIWebView alloc]initWithFrame:CGRectMake(10, 10, SCREEN_WIDTH, 480)];
[webView setBackgroundColor:[UIColor clearColor]];
[webView setOpaque:NO];
webView.delegate = self;
[scrollView addSubview:webView];
}
After enter the view, If I receive message:
- (void)updateJournalView:(NSArray *)journals {
NSString *descHtml = [self getHtmlDesc:journals];
[webView loadHTMLString:descHtml baseURL:nil];
}
getHtmlDesc method will return the html string quickly.
from load log, you can see it take about 5s to load.
2012-11-26 20:34:35.322 test[8456:c07] ====start load 2012-11-26 12:34:35 +0000:
2012-11-26 20:34:39.890 test[8456:c07] ====finish load 2012-11-26 12:34:39 +0000:
Following is UIWebViewDelegate method:
- (void)webViewDidFinishLoad:(UIWebView *)aWebView {
CGRect frame = aWebView.frame;
frame.size.height = 1;
aWebView.frame = frame;
CGSize fittingSize = [aWebView sizeThatFits:CGSizeZero];
frame.size = fittingSize;
aWebView.frame = frame;
scrollView.contentSize = CGSizeMake(SCREEN_WIDTH, fittingSize.height);
NSLog(#"====finish load %#:", [NSDate date]);
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType {
NSURL *url = [request URL];
if ([[url scheme] isEqualToString:#"redirect"] &&
[[url host] isEqualToString:#"opp_detail"]) {
NSString *oppIdStr = [[url path] stringByReplacingOccurrencesOfString:#"/player_id=" withString:#""];
if (oppIdStr && [oppIdStr length]) {
NSNumber *oppId = [NSNumber numberWithInt:[oppIdStr intValue]];
if ([oppId intValue] != gcontext.me.id) {
[screenNav gotoOppDetailScreen:[oppId intValue]];
}
}
}
return YES;
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType {
NSURL *url = [request URL];
if ([[url scheme] isEqualToString:#"redirect"] &&
[[url host] isEqualToString:#"opp_detail"]) {
NSString *oppIdStr = [[url path] stringByReplacingOccurrencesOfString:#"/player_id=" withString:#""];
if (oppIdStr && [oppIdStr length]) {
NSNumber *oppId = [NSNumber numberWithInt:[oppIdStr intValue]];
if ([oppId intValue] != gcontext.me.id) {
[screenNav gotoOppDetailScreen:[oppId intValue]];
}
}
}
return YES;
}
- (void)webViewDidStartLoad:(UIWebView *)webView{
NSLog(#"====start load %#:", [NSDate date]);
}
Please give me a hand, why it is so slow when loadHTMLString with UIWebView?
If there is nothing heavy to render, then it's possible that all about slow disk operations, that are performing when you're reading your html string.
https://stackoverflow.com/a/3400892/1851930

Get the Query Of a UIWebView URL

Hey guys I'm trying to find a way to specifically grab the Query String out of the URL that my UIWebView currently has loaded up.
So for example:
www.google.com?page=235
I want to end up with a NSString with the text "page=235".
Or even better Page at a NSData Key of Title and 235 at a Key of ID.
Im basically trying to organise the Query String into useable data.
In my project I have a button:
[HTML appendString:#"<a href='didtap://goto?Page=56'>Post Comment</a>"];
That i access with checking the absolute URL to see if the button was fired.
Is there any way to profile the information the way i want to?
I create the demo what you want get which is describe further..
Following is the viewcontroller.h file code
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController{
NSURL *Url;
}
#property(nonatomic,retain)IBOutlet UIWebView *webVctr;
#end
This may helping to solve your problem
Thanks
Following is the viewcontroller.m file code
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize webVctr = _webVctr;
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSLog(#"%#",request);
Url = [request URL];
// if ([[UrlParts objectAtIndex:(1)] isEqualToString:#"NeverGonnaFindMe"]) {
// CONVERT TO STRING AN CLEAN
NSString *urlResources = [Url resourceSpecifier];
urlResources = [urlResources stringByReplacingOccurrencesOfString:#"?" withString:#"/"];
// SEPORATE OUT THE URL ON THE /
NSArray *urlResourcesArray = [urlResources componentsSeparatedByString:#"/"];
// THE LAST OBJECT IN THE ARRAY
NSString *urlParamaters = [urlResourcesArray objectAtIndex:([urlResourcesArray count]-1)];
// SEPORATE OUT THE URL ON THE &
NSArray *urlParamatersArray = [urlParamaters componentsSeparatedByString:#"&"];
if([urlParamatersArray count] == 1) {
NSString *keyValue = [urlParamatersArray objectAtIndex:(0)];
NSArray *keyValueArray = [keyValue componentsSeparatedByString:#"="];
if([[keyValueArray objectAtIndex:(0)] isEqualToString:#"page"]) {
NSLog(#"%#",[keyValueArray objectAtIndex:1]);
}
[self dismissModalViewControllerAnimated:YES];
return NO;
}
return YES;
}
// ACTIVITY INDICATOR
- (void)webViewDidStartLoad:(UIWebView *)webView{
/// [_activityIndicator startAnimating];
NSLog(#"Resting to server");
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
// [_activityIndicator stopAnimating];
NSLog(#"Finish request server");
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
NSLog(#"Error");
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *fullAuthUrlString =[[NSString alloc] initWithFormat:#"www.google.com?page=235"];
NSURL *authUrl = [NSURL URLWithString:fullAuthUrlString];
NSURLRequest *myRequest = [[NSURLRequest alloc] initWithURL:authUrl];
[self.webVctr loadRequest:myRequest];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
#end
To get the query string, get the query string of a NSURL object.
NSURL *url = …;
NSString *queryString = url.query;
For more information, see Accessing the Parts of the URL in the NSURL class documentation.