I'm trying to add a Rate App button on my iOS Application and I've looked everywhere online by trying different ways of doing it but none of them have worked.
Here's what I've tried
1.
let appId = 1040912970
#IBAction func btnRateApp(sender: UIButton) {
let url = "itunes.apple.com/app/id\(appId)"
UIApplication.sharedApplication().openURL(NSURL(string: url)!)
}
2.
let appId = 1040912970
#IBAction func btnRateApp(sender: UIButton) {
let urlString = "http://itunes.apple.com/app/id\(appId)?mt=8"
let url = NSURL(string: urlString)
UIApplication.sharedApplication().openURL(url!)
}
3.
#IBAction func btnRateApp(sender: UIButton) {
UIApplication.sharedApplication().openURL(NSURL(string: url)!)
UIApplication.sharedApplication().openURL(NSURL(string:"https://itunes.apple.com/us/app/wsw-song-chants/id1040912970?ls=1&mt=8")!);
}
4.
#IBAction func btnRateApp(sender: UIButton) {
UIApplication.sharedApplication().openURL(NSURL(string : "itms-apps://itunes.apple.com/app/id1040912970")!);
}
When do this one above and click the button, a message on the output console will say
ERROR: There is no registered handler for URL scheme itms-apps Message
from debugger: Terminated due to signal 15
I've also checked if my app Id is correct which shows on itunes connect.
First and foremost you must use store-kit in order to actually have in-app ratings.
Secondly check iRate GitHub Page
It's a very common requirement and this Library will handle it.
Related
I would like to redirect the user to an app that could be selected in UIActivityViewController.
For example, the "Message" app is often shown in UIActivityViewController. How could I,in advance, directly redirect the user to this app without showing the UIActivityViewController?
I would be glad to know if someone can help me out.
If you need to open the Messages App, it's simple.
#IBAction func openMessagesApp(sender: UIButton){
// Swift 3
UIApplication.sharedApplication().openURL(NSURL(string: "sms:")!)
// Swift 4
UIApplication.shared.open(URL(string: "sms:")!, options: [:], completionHandler: nil)
}
Try this one!
#IBAction func openMessagesApp(sender: UIButton){
let sms = "sms:\(number)&body=\(message or link)"
let url = URL(string:sms)!
let shared = UIApplication.shared
if(shared.canOpenURL(url)){
shared.openURL(url)
} else{
print("unable to send message")
}
}
When I open the iOS Facebook app with
fb://profile/44083897053
the app opens and goes to the proper page as expected.
When I use
fb://profile/philamuseum
the app opens, but I am taken to my timeline.
Can anyone explain why this is happening?
The code being used is:
#IBAction func gotoFacebook(_ sender: Any) {
UIApplication.tryURL(urls:["fb://profile/\(self.facebookUser)/", "https://www.facebook.com/\(self.facebookUser)"])
}
. . . .
extension UIApplication {
class func tryURL(urls: [String]) {
let application = UIApplication.shared
for url in urls {
if application.canOpenURL(URL(string: url)!) {
application.open(URL(string: url)!)
return
}
}
}
I've looked at number of questions re opening facebook from an iOS app here and elsewhere and have not found any recent answer that bears on this issue.
New here to Xcode and Swift. I am working on an IOT app that enables me to switch a light on at a distance through a button on my today extension.
So I activated app groups and I am using UserDefaults to share info between app and widget. My logic being when button is pressed on the widget it returns a bool true. And if it returns true, I activate for now what is a LED on my ESP8266.
However, this doesn't seem to work, when I click the button nothing happens. What am I doing wrong? Any help or hints would be great! Thank you.
In viewcontroller.swift
override func viewDidLoad() {
defaults?.synchronize()
let Distribute = defaults?.bool(forKey: "Distribute")
if Distribute == true {
let requestURL = NSURL(string: led1on_URL)
// Instantiate an NSURLRequest object using the
// requestURL NSURL
let request = NSURLRequest(url: requestURL! as URL)
// Use the webview to send the request to the
// request NSURLRequest
View1.loadRequest(request as URLRequest)
super.viewDidLoad()
#IBAction func LED_control(_ sender: UIButton) {
}
}
In todayviewcontroller I have:
#IBAction func ButtonSnd(_ sender: Any) {
defaults?.set(true, forKey: "Distribute") //Bool Data Type
//Pass anything with this line
//defaults?.set("\(aNumber)", forKey: "userKey")
defaults?.synchronize()
print("Buttonpressed")
}
}
I'm adding an iMessage extension target to my app. The extension is supposed to send a message that has a url attribute. The behaviour I'm expecting when a user touches the message is to open the browser using the url attribute of the message.
I have a button in my messageView which executes this code:
#IBAction func labelButton(_ sender: Any) {
let layout = MSMessageTemplateLayout()
layout.imageTitle = "iMessage Extension"
layout.caption = "Hello world!"
layout.subcaption = "Test sub"
guard let url: URL = URL(string: "https://google.com") else { return }
let message = MSMessage()
message.layout = layout
message.summaryText = "Sent Hello World message"
message.url = url
activeConversation?.insert(message, completionHandler: nil)
}
If I touch the message, it expands the MessageViewController
I have then added this:
override func didSelect(_ message: MSMessage, conversation: MSConversation) {
if let message = conversation.selectedMessage {
// message selected
// Eg. open your app:
self.extensionContext?.open(message.url!, completionHandler: nil)
}
}
And now, when I touch the message, it opens my main app but still not my browser.
I have seen on another post (where I cannot comment, thus I opened this post) that it is impossible to open in Safari but I have a news app which inserts links to articles and allows with a click on the message to open the article in a browser window, while the app is installed.
So, can someone please tell how I can proceed to force opening the link in a browser window?
Thank you very much.
Here is a trick to insert a link in a message. It does not allow to create an object that has an url attribute but just to insert a link directly which will open in the default web browser.
activeConversation?.insertText("https://google.com", completionHandler: nil)
I have published a sample on github showing how to launch a URL from inside an iMessage extension. It just uses a fixed URL but the launching code is what you need.
Copying from my readme
The obvious thing to try is self.extensionContext.open which is documented as Asks the system to open a URL on behalf of the currently running app extension.
That doesn't work. However, you can iterate back up the responder chain to find a suitable handler for the open method (actually the iMessage instance) and invoke open with that object.
This approach works for URLs which will open a local app, like settings for a camera, or for web URLs.
The main code
#IBAction public func onOpenWeb(_ sender: UIButton) {
guard let url = testUrl else {return}
// technique that works rather than self.extensionContext.open
var responder = self as UIResponder?
let handler = { (success:Bool) -> () in
if success {
os_log("Finished opening URL")
} else {
os_log("Failed to open URL")
}
}
let openSel = #selector(UIApplication.open(_:options:completionHandler:))
while (responder != nil){
if responder?.responds(to: openSel ) == true{
// cannot package up multiple args to openSel so we explicitly call it on the iMessage application instance
// found by iterating up the chain
(responder as? UIApplication)?.open(url, completionHandler:handler) // perform(openSel, with: url)
return
}
responder = responder!.next
}
}
I have been trying to add a 'Follow us on Twitter' button to my app, however I have ran into a few issues.
First of all, if the user does not have Twitter installed, the code that I intended to redirect them to the website version of Twitter instead, doesn't seem to work.
Also, how can I handle situations when the users is offline? I would like to display a UIAlert to warn them that they must have a connection to use Twitter.
Here is my code:
#IBAction func followOnTwitter(sender: AnyObject) {
if UIApplication.sharedApplication().openURL(NSURL.URLWithString("twitter://user?screen_name=AffordIt_App")) {
if UIApplication.sharedApplication().openURL(NSURL.URLWithString("https://twitter.com/AffordIt_App")) {
}
}
}
From what I understand you need to see if the user has Twitter installed first.
#IBAction func followOnTwitter(sender: AnyObject) {
let screenName = "Your Twitter Handle"
let appURL = NSURL(string: "twitter://user?screen_name=\(screenName)")!
let webURL = NSURL(string: "https://twitter.com/\(screenName)")!
let application = UIApplication.sharedApplication()
if application.canOpenURL(appURL) {
application.openURL(appURL)
} else {
application.openURL(webURL)
}
}
I am new to this site and apologize if I am not posting in the proper format.