How to integrate Skype in my iPhone application - ios

I am new to iOS. I want to integrate Skype in my iPhone application,for this I have searched lot but I have not found a solution for this
How can I get Skype SDK for integration. How can I integrate Skype API in my application. Is there any other way to make developer Skype account
If your people having any sample code please post that.Please help me. Many Thanks.
I have tried some code please see that below but using that code my simulator it's showing alert like below image
my code:-
- (IBAction)skypeMe:(id)sender {
BOOL installed = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"skype:"]];
if(installed)
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"skype:echo123?call"]];
}
else
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://itunes.com/apps/skype/skype"]];
}
}

For Swift 3.0 It opens itunes url if it is not installed, otherwise it will open skype.
#IBAction func btnSkypeLinkPressed(_ sender : UIButton) {
let installed = UIApplication.shared.canOpenURL(NSURL(string: "skype:")! as URL)
if installed {
UIApplication.shared.openURL(NSURL(string: "skype:skypeID")! as URL)
} else {
UIApplication.shared.openURL(NSURL(string: "https://itunes.apple.com/in/app/skype/id304878510?mt=8")! as URL)
}
}
and in plist add:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>skype</string>
</array>
Hope it will work for swift users Thanks.

Here is your swift code:
Swift
#IBAction func skypeMe(sender: AnyObject) {
let installed = UIApplication.sharedApplication().canOpenURL(NSURL(string: "skype:")!)
if installed {
UIApplication.sharedApplication().openURL(NSURL(string: "skype:echo123?call")!)
} else {
UIApplication.sharedApplication().openURL(NSURL(string: "https://itunes.apple.com/in/app/skype/id304878510?mt=8")!)
}
}
Objective-C
- (IBAction)skypeMe:(id)sender {
BOOL installed = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"skype:"]];
if(installed){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"skype:echo123?call"]];
} else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"https://itunes.apple.com/in/app/skype/id304878510?mt=8"]];
}
}
I have changed skype URL for iTunes in this code and tested it with device and both URL is working fine.

in addition to #Dharmesh's answer, in iOS9 you must add the application you want to query for 'canOpenUrl' to you plist, under LSApplicationQueriesSchemes key
see this answer: https://stackoverflow.com/a/30988328/1787109

Using Swift 5 you can integrate "one to one" call and also one to many call in skype
#IBAction func btnStartSkypeCall(_ sender: UIButton) {
var installed: Bool? = nil
if let url = URL(string: "skype:") {
installed = UIApplication.shared.canOpenURL(url)
}
if installed ?? false {
if self.mainModelView.eventList!.students?.count ?? 0 <= 1{
if let url = URL(string: "skype:SkypeID?call&video=true") {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}else if self.mainModelView.eventList!.students?.count ?? 0 > 1{
if let url = URL(string: "skype:test_skype;test2_skype;test3_skype?call&video=true") {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}else{
print("Student list is empty")
}
} else {
if let url = URL(string: "https://itunes.apple.com/in/app/skype/id304878510?mt=8") {
UIApplication.shared.open(URL(string:"\(url)")!)
}
}
}
To start a chat use the schema
skype:user?chat
To start a video call use
skype:user?call&video=true
You must be add in plist file
<key>LSApplicationQueriesSchemes</key>
<array>
<string>skype</string>
</array>

Related

iOS How to implement open host app in broadcast upload extension?

I see other live app can open host app when use control center record.
[self.extensionContext openURL:YOUR_NSURL completionHandler:nil];
or
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:#"myapp://"]]];
or
func openURL(_ url: URL) -> Bool {
var responder: UIResponder? = self
while responder != nil {
if let application = responder as? UIApplication {
return application.perform(#selector(openURL(_:)), with: url) != nil
}
responder = responder?.next
}
return false
}
is doesn't work.any one know this?
Thank you for you time.best wishes

How can I programmatically determine if a URL is a Universal Link or just a regular web URL?

On iOS, how can I programmatically determine if a URL is a Universal Link or just a regular web URL?
Let's say you are about to launch the URL http://www.yelp.com from your own iOS app. (http://www.yelp.com is a fully registered universal link.)
Case one) the user doesn't have the app installed -> You want to show them the website in an IN-APP webview.
Case two) the user does have the app installed -> You want to launch out of your app and deep link directly to the the yelp app by using [[UIApplication sharedApplication] openURL:URL]; instead of presenting a webview in app.
Here is the problem:
All you get to work with is the string url: "http://www.yelp.com" Your goal is to launch out to the yelp app if installed but present an in-app webview if yelp is not installed.
Note 1: This question is only about universal links. Please do not give answers which use URL Schemes.
Note 2: This question is not about specifically launching the yelp app. The solution should work for any url to determine if it is a universal link of an installed app.
Can you do this?
Detect if a link is universal using UIApplicationOpenURLOptionUniversalLinksOnly
Following is the solution:
[[UIApplication sharedApplication] openURL:url
options:#{UIApplicationOpenURLOptionUniversalLinksOnly: #YES}
completionHandler:^(BOOL success){
if(!success) {
// present in app web view, the app is not installed
}
}];
I resolved this issue with my Swift 4 class below. It also uses embedded Safari Browser if possible. You can follow a similar method in your case too.
import UIKit
import SafariServices
class OpenLink {
static func inAnyNativeWay(url: URL, dontPreferEmbeddedBrowser: Bool = false) { // OPEN AS UNIVERSAL LINK IF EXISTS else : EMBEDDED or EXTERNAL
if #available(iOS 10.0, *) {
// Try to open with owner universal link app
UIApplication.shared.open(url, options: [UIApplication.OpenExternalURLOptionsKey.universalLinksOnly : true]) { (success) in
if !success {
if dontPreferEmbeddedBrowser {
withRegularWay(url: url)
} else {
inAnyNativeBrowser(url: url)
}
}
}
} else {
if dontPreferEmbeddedBrowser {
withRegularWay(url: url)
} else {
inAnyNativeBrowser(url: url)
}
}
}
private static func isItOkayToOpenUrlInSafariController(url: URL) -> Bool {
return url.host != nil && (url.scheme == "http" || url.scheme == "https") //url.host!.contains("twitter.com") == false
}
static func inAnyNativeBrowser(url: URL) { // EMBEDDED or EXTERNAL BROWSER
if isItOkayToOpenUrlInSafariController(url: url) {
inEmbeddedSafariController(url: url)
} else {
withRegularWay(url: url)
}
}
static func inEmbeddedSafariController(url: URL) { // EMBEDDED BROWSER ONLY
let vc = SFSafariViewController(url: url, entersReaderIfAvailable: false)
if #available(iOS 11.0, *) {
vc.dismissButtonStyle = SFSafariViewController.DismissButtonStyle.close
}
mainViewControllerReference.present(vc, animated: true)
}
static func withRegularWay(url: URL) { // EXTERNAL BROWSER ONLY
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [UIApplication.OpenExternalURLOptionsKey(rawValue: "no"):"options"]) { (good) in
if !good {
Logger.log(text: "There is no application on your device to open this link.")
}
}
} else {
UIApplication.shared.openURL(url)
}
}
}

Open Gmail app from my app

I'm trying to send an email from my app. But what I want is if user is having Gmail app on his/her phone, then mail should be sent using it. If Gmail app is unavailable then the user should be redirected to Mailbox.
So how can I know if user contains Gmail app and how can I redirect user to it.
Setup for iOS9+
As explained here, if you're on iOS9+, don't forget to add googlegmail to LSApplicationQueriesSchemes on your info.plist
Code to open GMail
Then, you can do the same as the accepted answer (below is my swift 2.3 version):
let googleUrlString = "googlegmail:///co?subject=Hello&body=Hi"
if let googleUrl = NSURL(string: googleUrlString) {
// show alert to choose app
if UIApplication.sharedApplication().canOpenURL(googleUrl) {
if #available(iOS 10.0, *) {
UIApplication.sharedApplication().openURL(googleUrl, options: [:], completionHandler: nil)
} else {
UIApplication.sharedApplication().openURL(googleUrl)
}
}
}
You need to use custom URL Scheme. For gmail application its:
googlegmail://
If you want to compose a message there you can add more parameters to this URL:
co?subject=Example&body=ExampleBody
You can determinate if any kind of application is installed using this code (just replace customURL obviously for an other apps):
NSString *customURL = #"googlegmail://";
if ([[UIApplication sharedApplication]
canOpenURL:[NSURL URLWithString:customURL]])
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:customURL]];
}
else
{
//not installed, show popup for a user or an error
}
For Swift 3.0+
Notes:
This solution shows how to use spaces or newlines in the arguments to the URL (Gmail may not respect the newlines).
It is NOT necessary to register with LSApplicationQueriesSchemes as long as you don't call canOpenURL(url). Just try and use the completion handler to determine if it succeeded.
let googleUrlString = "googlegmail:///co?to=\(address.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? "")&subject=\(subject.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? "")&body=\(buildInfo.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? "")"
if let googleUrl = URL(string: googleUrlString) {
UIApplication.shared.open(googleUrl, options: [:]) {
success in
if !success {
// Notify user or handle failure as appropriate
}
}
}
else {
print("Could not get URL from string")
}
I couldn't figure out why this wasn't working for me until I realised I was targetting a info_development.plist instead of the production-file info.plist
If you're like me and happen to have multiple Plists (one for development, one for prod etc) make sure you edit it everywhere. ;-)
Swift 5
These answers can open gmail but what if the user do not have gmail installed in the device? In that case I have handled opening apple mail/outlook/yahoo/spark. If none of them are present, I am showing an alert.
#IBAction func openmailAction() {
if let googleUrl = NSURL(string: "googlegmail://") {
openMail(googleUrl)
} else if let mailURL = NSURL(string: "message://") {
openMail(mailURL)
} else if let outlookURL = NSURL(string: "ms-outlook://") {
openMail(outlookURL)
} else if let yahooURL = NSURL(string: "ymail://") {
openMail(yahooURL)
} else if let sparkUrl = NSURL(string: "readdle-spark://") {
openMail(sparkUrl)
} else {
// showAlert
}
}
func openMail(_ url: NSURL) {
if UIApplication.shared.canOpenURL(url as URL) {
UIApplication.shared.open(url as URL, options: [:], completionHandler: nil)
}
}
You might also may have to add this in the plist
<key>LSApplicationQueriesSchemes</key>
<array>
<string>googlegmail</string>
<string>ms-outlook</string>
<string>readdle-spark</string>
<string>ymail</string>
</array>

How to launch Safari and open URL from iOS app

On the settings page, I want to include three links to
My app support site
YouTube app tutorial
My primary site (ie: linked to a 'Created by Dale Dietrich' label.)
I've searched this site and the web and my documentation and I've found nothing that is obvious.
NOTE: I don't want to open web pages within my app. I just want to send the link to Safari and that link be open there. I've seen a number of apps doing the same thing in their Settings page, so it must be possible.
Here's what I did:
I created an IBAction in the header .h files as follows:
- (IBAction)openDaleDietrichDotCom:(id)sender;
I added a UIButton on the Settings page containing the text that I want to link to.
I connected the button to IBAction in File Owner appropriately.
Then implement the following:
Objective-C
- (IBAction)openDaleDietrichDotCom:(id)sender {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.daledietrich.com"]];
}
Swift
(IBAction in viewController, rather than header file)
if let link = URL(string: "https://yoursite.com") {
UIApplication.shared.open(link)
}
Note that we do NOT need to escape string and/or address, like:
let myNormalString = "https://example.com";
let myEscapedString = myNormalString.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)!
In fact, escaping may cause opening to fail.
Swift Syntax:
UIApplication.sharedApplication().openURL(NSURL(string:"http://www.reddit.com/")!)
New Swift Syntax for iOS 9.3 and earlier
As of some new version of Swift (possibly swift 2?), UIApplication.sharedApplication() is now UIApplication.shared (making better use of computed properties I'm guessing). Additionally URL is no longer implicitly convertible to NSURL, must be explicitly converted with as!
UIApplication.sharedApplication.openURL(NSURL(string:"http://www.reddit.com/") as! URL)
New Swift Syntax as of iOS 10.0
The openURL method has been deprecated and replaced with a more versatile method which takes an options object and an asynchronous completion handler as of iOS 10.0
UIApplication.shared.open(NSURL(string:"http://www.reddit.com/")! as URL)
Here one check is required that the url going to be open is able to open by device or simulator or not. Because some times (majority in simulator) i found it causes crashes.
Objective-C
NSURL *url = [NSURL URLWithString:#"some url"];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}
Swift 2.0
let url : NSURL = NSURL(string: "some url")!
if UIApplication.sharedApplication().canOpenURL(url) {
UIApplication.sharedApplication().openURL(url)
}
Swift 4.2
guard let url = URL(string: "some url") else {
return
}
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
Take a look at the -openURL: method on UIApplication. It should allow you to pass an NSURL instance to the system, which will determine what app to open it in and launch that application. (Keep in mind you'll probably want to check -canOpenURL: first, just in case the URL can't be handled by apps currently installed on the system - though this is likely not a problem for plain http:// links.)
And, in case you're not sure if the supplied URL text has a scheme:
NSString* text = #"www.apple.com";
NSURL* url = [[NSURL alloc] initWithString:text];
if (url.scheme.length == 0)
{
text = [#"http://" stringByAppendingString:text];
url = [[NSURL alloc] initWithString:text];
}
[[UIApplication sharedApplication] openURL:url];
The non deprecated Objective-C version would be:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://apple.com"] options:#{} completionHandler:nil];
Swift 3
Solution with a Done button
Don't forget to import SafariServices
if let url = URL(string: "http://www.yoururl.com/") {
let vc = SFSafariViewController(url: url, entersReaderIfAvailable: true)
present(vc, animated: true)
}
Swift 3.0
if let url = URL(string: "https://www.reddit.com") {
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:])
} else {
UIApplication.shared.openURL(url)
}
}
This supports devices running older versions of iOS as well
Because this answer is deprecated since iOS 10.0, a better answer would be:
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}else{
UIApplication.shared.openURL(url)
}
y en Objective-c
[[UIApplication sharedApplication] openURL:#"url string" options:#{} completionHandler:^(BOOL success) {
if (success) {
NSLog(#"Opened url");
}
}];
Swift 5:
func open(scheme: String) {
if let url = URL(string: scheme) {
if #available(iOS 10, *) {
UIApplication.shared.open(url, options: [:],
completionHandler: {
(success) in
print("Open \(scheme): \(success)")
})
} else {
let success = UIApplication.shared.openURL(url)
print("Open \(scheme): \(success)")
}
}
}
Usage:
open(scheme: "http://www.bing.com")
Reference:
OpenURL in iOS10
openURL(:) was deprecated in iOS 10.0, instead you should use the following instance method on UIApplication: open(:options:completionHandler:)
Example using Swift
This will open "https://apple.com" in Safari.
if let url = URL(string: "https://apple.com") {
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}
https://developer.apple.com/reference/uikit/uiapplication/1648685-open
In SWIFT 3.0
if let url = URL(string: "https://www.google.com") {
UIApplication.shared.open(url, options: [:])
}
Try this:
NSString *URL = #"xyz.com";
if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:URL]])
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:URL]];
}
In Swift 1.2, try this:
let pth = "http://www.google.com"
if let url = NSURL(string: pth){
UIApplication.sharedApplication().openURL(url)
Swift 4 solution:
UIApplication.shared.open(NSURL(string:"http://yo.lo")! as URL, options: [String : Any](), completionHandler: nil)

How can I launch Safari from an iPhone app?

This might be a rather obvious question, but can you launch the Safari browser from an iPhone app?
should be the following :
NSURL *url = [NSURL URLWithString:#"http://www.stackoverflow.com"];
if (![[UIApplication sharedApplication] openURL:url]) {
NSLog(#"%#%#",#"Failed to open url:",[url description]);
}
UIApplication has a method called openURL:
example:
NSURL *url = [NSURL URLWithString:#"http://www.stackoverflow.com"];
if (![[UIApplication sharedApplication] openURL:url]) {
NSLog(#"%#%#",#"Failed to open url:",[url description]);
}
you can open the url in safari with this:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"https://www.google.com"]];
Maybe someone can use the Swift version:
In swift 2.2:
UIApplication.sharedApplication().openURL(NSURL(string: "https://www.google.com")!)
And 3.0:
UIApplication.shared().openURL(URL(string: "https://www.google.com")!)
With iOS 10 we have one different method with completion handler:
ObjectiveC:
NSDictionary *options = [NSDictionary new];
//options can be empty
NSURL *url = [NSURL URLWithString:#"http://www.stackoverflow.com"];
[[UIApplication sharedApplication] openURL:url options:options completionHandler:^(BOOL success){
}];
Swift:
let url = URL(string: "http://www.stackoverflow.com")
UIApplication.shared.open(url, options: [:]) { (success) in
}
In swift 4 and 5, as OpenURL is depreciated, an easy way of doing it would be just
if let url = URL(string: "https://stackoverflow.com") {
UIApplication.shared.open(url, options: [:])
}
You can also use SafariServices. Something like a Safari window within your app.
import SafariServices
...
if let url = URL(string: "https://stackoverflow.com") {
let safariViewController = SFSafariViewController(url: url)
self.present(safariViewController, animated: true)
}
In Swift 3.0, you can use this class to help you communicate with. The framework maintainers have deprecated or removed previous answers.
import UIKit
class InterAppCommunication {
static func openURI(_ URI: String) {
UIApplication.shared.open(URL(string: URI)!, options: [:], completionHandler: { (succ: Bool) in print("Complete! Success? \(succ)") })
}
}

Resources