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

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

Related

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)
}
}
}

How to call a phone number from ios native app automatically

I want to call a phone number from ios native app
the code is like this:
NSString *allString = [NSString stringWithFormat:#"tel:%#",phoneNum];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:allString]]
In IOS10.2, Some one can auto-call directly, but others got a confirm dialog.
So, what should I do to let all iphones can auto call directly?
Use in your viewcontroller
func doPhoneCall(_ number: String?) {
if var number = number {
number = number.replacingOccurrences(of: " ", with: "")
if let phoneCallURL = URL(string:"tel://\(number)") {
openURL(phoneCallURL)
}
}
}
func openURL(_ url: URL) {
let application = UIApplication.shared
if (application.canOpenURL(url)) {
application.openURL(url);
}
}

Open My application from my keyboard extension in swift 3.0

I am trying to open from my keyboard extension. I am having custom keyboard and I have add that keyboard from setting. On my custom keyboard there is one button “Show More”, and I want to open my app on this button click.
So I have tried following code :
let context = NSExtensionContext()
context.open(url! as URL, completionHandler: nil)
var responder = self as UIResponder?
while (responder != nil) {
if responder?.responds(to: Selector("openURL:")) == true {
responder?.perform(Selector("openURL:"), with: url)
}
responder = responder!.next
}
It is working successfully, but as we know in swift Selector("method_name:") is deprecated and use #selector(classname.methodname(_:)) instead so it is giving warning. And I want to solve that warning. So I have tried as Xcode automatically suggested :
if responder?.responds(to: #selector(UIApplication.openURL(_:))) == true {
responder?.perform(#selector(UIApplication.openURL(_:)), with: url)
}
Also tried :
if responder?.responds(to: #selector(NSExtensionContext.open(_:))) == true {
responder?.perform(#selector(NSExtensionContext.open(_:)), with: url)
}
I have also tried others possible ways, but no luck. If anyone know how to do, please let me know.
I referred this link, Julio Bailon’s answer :
openURL not work in Action Extension
Swift 5.0:
Open Info.plist of hosting app.
Add Url Types -> Item 0 -> Url Schemes -> Item 0 : "yourappname"
Add
Url Types -> Item 0 -> Url Schemes -> URL Identifier: "your bundle
id"
Go to Keyboard App:
Add following code properly:
#objc func openURL(_ url: URL) {
return
}
func openApp(_ urlstring:String) {
var responder: UIResponder? = self as UIResponder
let selector = #selector(openURL(_:))
while responder != nil {
if responder!.responds(to: selector) && responder != self {
responder!.perform(selector, with: URL(string: urlstring)!)
return
}
responder = responder?.next
}
}
Call : openApp ("yourappname://your bundle id")
Following code works on Xcode 8.3.3, iOS10, Swift3 without any compiler warnings:
func openUrl(url: URL?) {
let selector = sel_registerName("openURL:")
var responder = self as UIResponder?
while let r = responder, !r.responds(to: selector) {
responder = r.next
}
_ = responder?.perform(selector, with: url)
}
guard let url = URL(string: UIApplicationOpenSettingsURLString) else { return }
extensionContext?.open(url, completionHandler: { (success) in
if !success {
var responder = self as UIResponder?
while (responder != nil){
let selectorOpenURL = NSSelectorFromString("openURL:")
if responder?.responds(to: selectorOpenURL) == true {
_ = responder?.perform(selectorOpenURL, with: url)
}
responder = responder?.next
}
}
})

How to integrate Skype in my iPhone application

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>

Swift, can't open second app using 'deep link'

It seems I can't open the second app using my method. Nothing happened. Is there any silly mistakes here?
My second app .plist file
My first app code
#IBAction func btnCRM(sender: AnyObject) {
var customURL: NSString = "CRM://"
if (UIApplication.sharedApplication().canOpenURL(NSURL(fileURLWithPath: customURL as String)!)){
UIApplication.sharedApplication().openURL(NSURL(fileURLWithPath: customURL as String)!)
}
}
In addition to the URL Schemes under Item 0, you need to add URL identifier which is CFBundleURLName, as outlined here.
try this code:
let url = NSURL(string: "CRM://")
if (UIApplication.sharedApplication().canOpenURL(url!)) {
UIApplication.sharedApplication().openURL(url!)
}
'openURL' was deprecated in iOS 10.0
Updated version:
guard let url = URL(string: "CRM://"), UIApplication.shared.canOpenURL(url) else {
return
}
UIApplication.shared.open(url, options: [:], completionHandler: nil)
Swift 5.7 2023
The code below opens the main application
private func openMainApp() {
self.extensionContext?.completeRequest(returningItems: nil, completionHandler: { _ in
guard let url = URL(string: self.appURL) else {
return
}
_ = self.openURL(url)
})
}
// Courtesy: https://stackoverflow.com/a/44499222/13363449 👇🏾
// Function must be named exactly like this so a selector can be found by the compiler!
// Anyway - it's another selector in another instance that would be "performed" instead.
#objc private 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
}

Resources