how to open the app store when clicking button - swift

enter image description hereI want to open the app store when I click a certain button but, I have looked everywhere, and the code I have tried takes me to a safari link or doesn't do anything at all. can anyone help me? what i want it to achieve is that i hit the button and it opens up the app store with my specified app
UPDATE: i tried the method below and it opened oped up safari saying it could open the page

Zenprogrammer79 if your using the iOS simulator the link won't work because there is no App Store on the simulator but it should work on a real iOS device

zenProgrammer79 if you have a link to another app in the App Store, you can put this code in the section of where your button gets pressed (the IBAction) (objective-c)
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"link to the application link looks like https://itunes.apple.com/au/app/sugar-calculator/id1000071935?mt=8"]];
if you are using swift i believe this will work
UIApplication.sharedApplication().openURL(NSURL(string: "https://itunes.apple.com/au/app/sugar-calculator/id1000071935?mt=8")!)
if this doesn't work then your link to the app is probably wrong.

Related

Xcode Swift 5 MacOs app empty window when archived but works when running it from Xcode

I am building an app for Mac which logs into a website based on login and password collected from textfield and secure text field, then app opens an url which is created in my app based on date range selection with use of two date picker cell calendars. Next app displays html data in webWiev (using WKWebView), converts html to string using extension NSAttributedString and then saves retrieved data as txt file. Everything works as expected as long as app is run from Xcode "play" button. Problem is if I archive this app and launch it, it will bring up an empty window without any button, calendar or textfield. There are no errors, no crash logs on organizer, nothing.
I decided to perform a little test. I build another view controller with only one button which upon clicking will show my app main view controller. After archiving this modified app and running it outside of Xcode a window shows view controller with one button which is correct. But after clicking it nothing happens. App works great if running "inside" Xcode, a pushbutton shows main ViewController correctly. Do You have any clue what can be wrong? thank You!
Edit 1. So I found a discussion on apple which mention this problem. It is associated with IB WKWebView and problem is already known since some time. Now I have to get around the problem. Apple forum link: https://forums.developer.apple.com/thread/116047
Did you embed WebKit.framework to your app?
After comment that I wrote, I founded a solution and solved with this method.
Please check it out.

How to open url in Safari and the get back to the app under UITests in Xcode 7?

This is my custom view where "LondonStreet" is a button.
When I tap that button I get url and open it in Safari (it works). Then I can go back, using "Back to Wishlist" button (it also works).
The problem is when I try to test this under UITests.
itemsTable.cells.elementBoundByIndex(0).buttons["addressButton"].tap() //press the button to open link in Safari
Along with this line:
app.statusBars.buttons["Back to Wishlist"].tap() //go back, doesn't work, although it was recorded by Xcode itself.
is an error:
UI Testing Failure - Failed to get screenshot within 5s.
And also in issue Navigator
UI Testing failure - Unable to update application state promptly.
Starting in iOS 11 you can interact with other applications using the XCUIApplication(bundleIdentifier:) initializer.
To get back to your app you'd do something like:
let myApp = XCUIApplication(bundleIdentifier: "my.app.bundle.id")
let safari = XCUIApplication(bundleIdentifier: "com.apple.mobilesafari")
// Perform action in your app that opens Safari
safari.wait(for: .runningForeground, timeout: 30)
myApp.activate() // <--- Go back to your app
UI Testing cannot interact with anything outside of your application. In your scenario, the framework can no longer do anything once your app opens Safari.
To verify this, try printing out the app's hierarchy once Safari opens. You will notice that nothing in Safari nor the navigation bar will show up - you will only see your app's information.
print(XCUIApplication().debugDescription)
To open specific url in Safari on iOS 15:
safari.textFields["Address"].tap()
safari.textFields["Address"].typeText("www.urlToOpen.com")
safari.keyboards.buttons["Go"].tap()

iPhone SDK - Add a "Add to Home Screen" button in a UIWebView

I have a native iPhone app, which has a UIWebView component to it. I am trying to see if I can replicate the "Add to Home Screen" button that is present in the tab bar options in Safari.
Is this possible inside a UIWebView within a native app?
Thanks!
Brett
[I presume your question is about replicating the action associated with add to home screen, rather than replicating the appearance of the button itself (which being pedantic is what you actually wrote).]
As others have said this isn't possible.
What you could do is programatically launch Safari from within your app and give it the URL of a page to load which is your page.
When your page is loaded it has some sort of animation and shows the user where the add to home screen button is and tell them to press it after clicking a link which is displayed in your web page. When the users click on the link it takes them to whatever page it is that you would like saved to the desktop, and you hope they follow your instructions.
If you register your app to handle a proprietary url scheme the users can get back to your app from within Safari by clicking on a link using your app's url scheme.
The web pages that you seed Safari with must however be remote pages, you cannot give Safari a page in your app's bundle or that your app has downloaded as Safari cannot read pages from your app's sandbox.
The short answer is no, you can't. Apple does not let you.
Here's a similar question which may help you come up with other possibilities:
Javascript for "Add to Home Screen" on iPhone?
If I had to think of a work around off the top of my head, you could create an javascript pop-up which instructs them how to. It could say something like tap this button to go to mobile safari then tap action -> add to home screen.
Execute the Javascript with UIWebView's method:
- (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script
Hope this helps.
You can use UIActivityViewController with your url as the activity items
NSArray *activityItems = #[title, url];
And then you can exclude the activities that you don't want. I think it´s the only way for now.

how to move moretab in iphone

in my applicaton,i have one directions tab in moretab.In directions tab, i displays the safari view through coding like this
NSString* url = #"http://maps.google.com/maps?saddr=33.68325,-117.834073&daddr=33.67425,-117.835073&dirflg=w";//[NSString stringWithFormat: #"http://maps.google.com/maps?q=%#",#"1101+E+Fletcher+Ave+Tampa+FL+33612"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
when click the directions tab it shows the safari browser.But my problem is after open the safari view, iam not able to move the more tab again. now what i want be done is ,when closing this safari view and reopen my application it directly shows the more tab not directions tab.How to do this.
Often times directing the user to Safari can be very confusing and some users don't understand how to come back. Consider using UIWebView instead for this since it stays inside your app and also provides you with the control that you are talking about now.
If you absolutely have to direct the user to safari I would take a look at this post that talk about how to catch the events of a user leaving your app and different states for that.

App terminating when button clicked

I am very new to iphone coding.
I followed this tutorial to make a button in an app, but instead of having it change the background colour in the app, I made it a weblink using:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.apple.com"]];
This all works find when doing it in a "Window based application", but if I follow the exact same guide when putting a button into a Tab Bar Application I run into trouble.
The app builds fine, but when I click the button the application just terminates.
Any ideas?
We'd need some actual code to really debug the matter but EXC_BAD_ACCESS means you're trying to access an object that has already been deallocated from memory.