i develop a calling program in the below way.
my main aim is enter the number in textfield and whenever i press the call button it convert
into the integer and then perform calling action.in xcode is there any possibility to create a
code for outgoing call?
And is there any possibility to block the incoming calls?
i am writing the code below way.
my .h file is
#interface mytextViewController : UIViewController
{
IBOutlet UILabel *enterphonenumber;
int currentNumber;
}
#property(nonatomic,retain)IBOutlet UILabel *enterphonenumber;
-(IBAction)call;
-(IBAction)press:(id)sender;
#end
my .m file is
-(IBAction)press:(id)sender
{
currentNumber = currentNumber*10 + (int)[sender tag];
enterphonenumber.text = [NSString stringWithFormat:#"%i",currentNumber];
}
-(IBAction)call
{
int x =[enterphonenumber.text intValue];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:x]];
//[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"%tel:9963610177"]];
NSLog(#"sample %#",[NSURL URLWithString:#"my phone number is calling"]);
}
And also how to examine it performs a calling
please any one help because i am the new to develop this application
Thanking you,
Try using the tel protocol.
if ([[[UIDevice currentDevice] model] isEqualToString:#"iPhone"])
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"tel://%d", number]]];
}
You cannot block any incoming calls.
You can't block any incoming calls in your app.
Related
I'm trying to call a method that's inside someClass from the AppDelegate class.
I usually create an instance and then using that instance, call the method. Like so:
FFAppDelegate *delegate = (FFAppDelegate *) [[UIApplication sharedApplication] delegate];
[delegate someMethod];
I use that ^^ quite a bit in my code and it works perfectly. What I want to do, is switch it around. Instead of calling a method INSIDE the AppDelegate, I want to call a method inside another class FROM the AppDelegate.
SomeClass *test = (SomeClass *) [[UIApplication sharedApplication] delegate];
[test someMethod];
In this case, I keep getting "Terminating app due to uncaught exception 'NSInvalidArgumentException'" error due to "unrecognized selector sent to instance".
Any light shed on the matter would be greatly appreciated! :)
[[UIApplication sharedApplication] delegate]; return your AppDelegate class , not SomeClass
you can use like this :
FFAppDelegate *delegate = (FFAppDelegate *) [[UIApplication sharedApplication] delegate];
[delegate someMethodForSomeClass];
And then in your AppDelegate code someMethodForSomeClass like this :
- (void)someMethodForSomeClass
{
SomeClass *someClass = _yourSomeClass;
[someClass someMethod];
}
Instantiate an instance of the class that you want to send the request from and make the method public (in the .h file). Then import that class into the app delegate and call it.
Like so...
YourClass * yourClassInstance = [[YourClass alloc] init];
[yourClassInstance someMethod];
in YourClass.h below the #interface you would declare the method like so
-(void)someMethod;
So anyone could access it.
For Example if you want to Create AlertView only Once and Use it in any UiViewController
So, you can make Method For UIAlertView and Call the Method When you Want
1)In your appDelegate.h file
#property (nonatomic, strong) UIAlertView *activeAlertView;
2) In your AppDelegate.m File
-(void)openAlert
{
NSString *strMsgPurchase = #"Write your message";
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Buy" message:strMsgPurchase delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Buy",#"Restore", nil];
[alert setTag:100];
[alert show];
self.activeAlertView = alert;
}
3) To Call the Method in which uiview you want
[((AppDelegate *)[[UIApplication sharedApplication] delegate])openAlert];
Note: Define -(void)openAlert Method in Appdelegate.h file
I am developing an application in which, I can initialize a call from the application. Is it possible to come back to the same place in the application where I was before the call, after the call is terminated? If it is possible, then how? Thank you in advance.
I believe you can not do what you are trying to do. Because once the user attends the call and terminates the call, the application currently active would be Dialer and you can not in no way make you application active.
Implement the following methods from the UIApplicationDelegate protocol:
applicationWillResignActive is called when the phone receives an incoming call
applicationWillTerminate is called when the user answers the call
applicationDidBecomeActive is called if the user choose not to answer the call
applicationWillTerminate will give a few seconds to save your apps current state.
Use NSUserDefaults to save state . When the app starts again you read your state from NSUserDefaults and restore the app to its previous state.
If you want to come back to your application after a phone call, need to change
[UIApplication sharedApplication] openURL:telURL];
to
UIWebView PhoneCallWebView = [[UIWebView alloc] init];
[PhoneCallWebView loadRequest:[NSURLRequest requestWithURL:telURL]];
and it works.
I hope this will help you...and this will back after in application after call ended.
NSString *aPhoneNo = #"9876543210";
NSURL *url= [NSURL URLWithString:aPhoneNo];
NSString *osVersion = [[UIDevice currentDevice] systemVersion];
if ([osVersion floatValue] >= 3.1)
{
UIWebView *webview = [[UIWebView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
[webview loadRequest:[NSURLRequest requestWithURL:url]];
webview.hidden = YES;
// Assume we are in a view controller and have access to self.view
[self.view addSubview:webview];
[webview release];
}
else
{
// On 3.0 and below, dial as usual
[[UIApplication sharedApplication] openURL: url];
}
According to Apple's documentation, in order to make phone call from my app, I need to implement the following protocols:
HTML link:
1-408-555-5555
Native application URL string:
tel:1-408-555-5555
However, upon completion of a phone call initiated from an HTML link inside a UIWebView, I am redirected right back to my application. But upon completion of a phone call made from a native application URL string, my iphone stays in the iphone's regular phone application, and if I want to return to my application I have to do so manually.
As far as I can tell from reading what others have said, there is no way to change this behavior.
Here is my question:
Is it true that it's impossible
to return to an application after
making a phone call from a native
application URL string?
Would there be any downside to
implementing a UIWebView instead of
a UILabel in situations where I
really wanted the user to be
redirected back to my application
after completing a phone call?
The simplest way seems to be:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"telprompt:0123456789"]];
You will get a prompt and your app will regain focus after the call is finished.
Behavior does differ between calling -[UIApplication openURL:] with a tel: URL, and clicking a link to the same URL in a UIWebView.
Using a UIWebView instead of a UILabel might have some downsides, but you don't have to actually display the UIWebView to get its tel URL handling behavior. Instead, just load a tel URL request in an instance of UIWebView without adding it to your view hierarchy.
For example:
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#interface PhoneCaller : NSObject
{
#private
UIWebView *webview;
}
- (void)callTelURL:(NSURL *)url;
#end
#implementation
- (id)init
{
self = [super init];
if (self)
{
webview = [[UIWebView alloc] init];
}
return self;
}
- (void)callTelURL:(NSURL *)url
{
[webview loadRequest:[NSURLRequest requestWithURL:url]];
}
- (void)dealloc
{
[webview release];
[super dealloc];
}
#end
Allow me to simplify a bit. All you need is this little snippet:
UIWebView *callWebview = [[UIWebView alloc] init];
NSURL *telURL = [NSURL URLWithString:#"tel:number-to-call"];
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
which I got here.
*Recently tested successfully on iOS 5.0.
The Eric's Brotto method still works in 5.1. You have to add the webview to the main view before the loadRequest, like this:
NSString *cleanedString = [[phoneNumber componentsSeparatedByCharactersInSet:[[NSCharacterSet characterSetWithCharactersInString:#"0123456789-+()"] invertedSet]] componentsJoinedByString:#""];
NSString *escapedPhoneNumber = [cleanedString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *telURL = [NSURL URLWithString:[NSString stringWithFormat:#"tel://%#", escapedPhoneNumber]];
UIWebView *mCallWebview = [[UIWebView alloc] init] ;
[self.view addSubview:mCallWebview];
[mCallWebview loadRequest:[NSURLRequest requestWithURL:telURL]];
(I added a phone number cleaner, to delete any non-number char that blocks this method)
I am having the UIButton name as "Buy now".If any one touch the button,the external link should open in the safari browser.How can i achieve this?
It's easy. You set the target and selector for the button, then inside the selector, you call safari to open your link.
Code to call Safari:
Objective-C
- (void)buttonPressed {
[[UIApplication sharedApplication]
openURL:[NSURL URLWithString: #"https://www.google.co.uk"]];
}
Swift 2.x
UIApplication.sharedApplication().openURL(NSURL(string: "https://www.google.co.uk")!)
Swift 3.x
UIApplication.shared.openURL(URL(string: "https://www.google.co.uk")!)
Create a button, and give it a target to a selector that opens Safari with the link.
Basic example:
Make a UIButton
UIButton *button = [[UIButton alloc] initWithFrame:...];
[button addTarget:self action:#selector(someMethod) forControlEvents:UIControlEventTouchUpInside];
Then the method to open the URL
-(void)someMethod {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: #"http://www.google.ca"]];
}
Don't forget to give your button a proper frame and title, and to add it to your view.
- (IBAction)buyNowButtonPressed {
NSString *s = [ NSString stringWithFormat:#"http://www.sample.com/buynowpage"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:s]];
}
openURL is deprecated from iOS 10 and use following instead.
UIApplication *application = [UIApplication sharedApplication];
NSURL *url = [NSURL URLWithString:#"http://www.yourDomain.com"];
[application openURL:url options:#{} completionHandler:nil];
In my iPhone app an UITextView is containing an URL. I want to open this URL in an UIWebView instead of opening it into safari?
My UITextView contains some data along with an URL. In some cases the no. of URLs can be more than one.
Thanks
Sandy
You can follow these steps:
Tick on the following properties in UITextView taken from Xib or Storyboard.
OR write these for textview taken dynamically.
textview.delegate=self;
textview.selectable=YES;
textView.dataDetectorTypes = UIDataDetectorTypeLink;
Now write the below delegate method :
-(BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange
{
NSLog(#"URL: %#", URL);
//You can do anything with the URL here (like open in other web view).
return NO;
}
I think you are searching for that.
The UITextView has the capability to detect URLs and embed hyperlinks accordingly. You can turn that option on in:
myTextView.dataDetectorTypes = UIDataDetectorTypeLink;
Then you need to configure your app to trap this URL request and let your application handle it. I published a boilerplate class on github that does this, which might be the easiest route: http://github.com/nbuggia/Browser-View-Controller--iPhone-.
The first step is to sub-class UIApplication so you can override who gets to take action on the 'openUrl' request. Here's what that class might look like:
#import <UIKit/UIKit.h>
#import "MyAppDelegate.h"
#interface MyApplication : UIApplication
-(BOOL)openURL:(NSURL *)url;
#end
#implementation MyApplication
-(BOOL)openURL:(NSURL *)url
{
BOOL couldWeOpenUrl = NO;
NSString* scheme = [url.scheme lowercaseString];
if([scheme compare:#"http"] == NSOrderedSame
|| [scheme compare:#"https"] == NSOrderedSame)
{
// TODO - Update the cast below with the name of your AppDelegate
couldWeOpenUrl = [(MyAppDelegate*)self.delegate openURL:url];
}
if(!couldWeOpenUrl)
{
return [super openURL:url];
}
else
{
return YES;
}
}
#end
Next, you need to update main.m to specify MyApplication.h as being the bonified delegate for your UIApplication class. Open main.m and change this line:
int retVal = UIApplicationMain(argc, argv, nil, nil);
to this
int retVal = UIApplicationMain(argc, argv, #"MyApplication", nil);
Finally, you need to implement the [(MyAppDelegate*) openURL:url] method to have it do what ever you would like with the URL. Like maybe open up a new view controller with a UIWebView in it, and show the URL. You could do something like this:
- (BOOL)openURL:(NSURL*)url
{
BrowserViewController *bvc = [[BrowserViewController alloc] initWithUrls:url];
[self.navigationController pushViewController:bvc animated:YES];
[bvc release];
return YES;
}
Hopefully that should work for you.
Assuming you have the following instances, that are also added to your UIView:
UITextView *textView;
UIWebView *webView;
and textView contains the URL string, you can load the contents of the URL into webView, as follows:
NSURL *url = [NSURL URLWithString:textView.text];
NSURLRequest *req = [NSURLRequest requestWithURL:url];
[webView loadRequest:req];