App terminating when button clicked - iphone

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.

Related

how to open the app store when clicking button

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.

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

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.

Return Back To Application From Browser

I'm implementing a website call on button touch(in iPhone), so my browser get called in that case and website get opened.
I'm using following code:
- (IBAction) websiteButtonTouched{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.google.com"]];
}
Now what I want is to COME BACK TO MY APPLICATION FROM BROWSER as In iPhone4.0 and Up the application remain running at background we only have to call that when browser quite...
Thanks In Advance.. :P
Why not create your own in-app browser? Just put a UIWebView inside a navigation controller then put an address bar and a search bar.
Please see this question:
iPhone - Open Application from Web Page
As for returning to application where you left off -- if the device supports backgrounding (iOS4+) and your backgrounded app wasn't unloaded (due to memory shortage), the app will return the point you left it.
However, you also have to handle the returning to correct point in app yourself, in the cases that the device doesn't support backgrounding, or app was unloaded due to memory shortage: you can do this by storing information about current state of the app before it exits.
This web page has some very nice flow charts which describe app backgrounding and foregrounding etc.:
http://www.cocoanetics.com/2010/07/understanding-ios-4-backgrounding-and-delegate-messaging

What does double-tapping on the home button exactly do?

What does double-tapping on the home button exactly do?
Does it list the applications running in background, OR
Does it list recently used applications?
I've implemented the "Application does not run in background" in my Info.plist file. In spite of this my application shows on double tapping the home button !! Yes I have tried a clean build.
It shows all recently-used apps, not just the multi-tasking ones. If you try to tap your app now, it will start exactly like it was first launched, displaying the launch image first before initializing (calling application:didFinishLaunchingWithOptions: and sending the relevant notifications).