Is there anyway to close iphone app just like user press the menu key? - iphone

Is there anyway to close iphone app just like user press the menu key?
I already know exit(0) , it works. But user experience not good, I want to scale the window first and then close the app, just like user press the menu key. Is this possible? Thanks!

This is not possible. Apple don't allow it. It's very poor user experience for an app to just exit even if it does look like they've pressed the home button. The user is in control of what happens and when an app exits.

Yes there is a way to close the iPhone app just like user presses the Home Key, But Apple strictly forbids to use this. Anyways here is the code:
[[UIApplication sharedApplication] suspend];

No, there is no way to do this, and quite honestly, there really isn't any good reason to do this. Users expect to control when the app closes, period.
What are you trying to gain by closing the app anyway?

Related

How to close System dialogs that appears on app crash?

I'm using xcuitest framework to automate mac application. I get system dialogs when the app is opened again after it crashes. I want to handle the dialog programmatically. But the dialog appears under the process `UserNotificationCenter' instead of the application under test. How can I handle the alert in such case?
You have two options:
Use InterruptionMonitor (documentation, use-case). This
approach is however kinda old and I found, that it does not work for
all dialogs and situations.
Create a method, which will wait for some regular app's button. If the app's button (or tab bar or other such XCUIElement) is visible and hittable after your app started, you can proceed with your test and if it's not, you can wait for the UserNotificationCenter dialog's button and identify&tap it by its string/position.
I'm using the second approach and its working much better, than the InterruptionMonitor. But it really depends on your app layout and use-case.
You should be able to revent it from appearing in the first place. Something like:
defaults write com.apple.CrashReporter DialogType none

UILocalNotification actions and snoozing

I'm working on a custom app for a client and am still relatively new to iOS development. The app involves setting reminders and I'm using UILocalNotifications. Now from my research the action on the notification will always run the app but I'm really hoping someone can correct me on that. Also from what I've read you are limited to the 'View' or 'Close' options. Ideally I'd love to have 3 buttons on the notification and not have to open the app to perform an action.
I'd like a 'dismiss' option, 'snooze' option, and an 'ok' option that dismisses the notification but runs some code in the background.
I came across a notification related question where somebody suggested opening the app with a modal view and presenting the options from there. Possible, just not as clean, I guess.
Any other ideas or is this what I have to do to achieve my desired functionality? If that's the case is there a way to close the app after I've selected one of my options from the modal view?
Thanks in advance.
That is not possible, as the notification is not created by your app but by the system, so you can't customize the appearance of the notification. (also in iOS 5, the user can choose to display the notifications as banners instead of alerts, which would hide any other button than the view and close button, if that were to be possible).
Secondly there is no way to close your app, as iOS is a user centric system, where the user takes the decision on whether to open or close app, and not the app itself.

iOS: Making an App terminate when leave screen

I've build a simple app activating something in hardware, not important.
Now I just want the app to terminate completely if the user leaves the screen, switches apps, gets a call, press the home button, etc.
I'm all mixed up by all the application states, I couldn't find the right place to handle it.
I guess I need to listen to an "going to sleep" event and put a termination command (exit!)
or something like that.
This is easier than what one might think.
In your app's plist file define (check) the option "Application does not run in background" (UIApplicationExitsOnSuspend), and you are done.

What's the rule under the displaying UIAlert message "app would like to use your current location"?

In my app I have two tabs. The first tab just controller with some functions.
The second tab has MapView with showUserLocation property YES.
As I know in general UIAlert message "app would like to use your current location" is displayed when app is launching, but in my raw app this message has time when I do the firs tap on my second tab.
Would you clarify me how can I manage this issue?
P.S.Sorry, but I didn't find any info about.
Thanks
It's actually better to only request location access when it's necessary. In many apps, some users might not even use the location-based features. Having it only pop up when they hit the second tab is perfectly fine.

On Android or iOS - how to approach the possibility of a service or app going into a broken state

...and this broken state persisting until a device restart, since a naive attempt to restart an app would not work. Many users are not savvy enough to know how to terminate services/backgrounded apps. If the user can't (or doesn't 'need to') close apps, then what about restarting apps which have gone wrong? ( It can happen :) ) If my app goes wrong on someone's phone and they cannot easily restart the app without restarting the phone, that seems like a problem. I am aware that apps and services can be terminated by navigating system menus or double tapping the home button etc. but - many users are not aware of these features. For this reason I am thinking of adding an explicit close button to my app which will kill everything to the best of my ability, such that on a subsequent launch the program runs from the beginning again. I realise this is not the 'recommended' approach. Thoughts?
Thoughts?
Don't do it. Instead you should put a FAQ entry on your apps website that says.
Q: My app does not run anymore. HELP!
A: First you should try to restart the app. If that doesn't work feel
free to contact me.
Here is how you do this on the iPhone,
iPad or iPod.
double press the home button. the
multi tasking bar appears.
[ some screen shots ]
long press the app icon and press the
little x that appears on the icon.
[ more screenshots ]
If you want to put buttons for functions that are not obvious for many users you end up with a button for everything. And I (as somebody who knows every function) don't want a button cluttered user interface.
You would be surprised how many emails I get about "how can I zoom?" (A: Pinch your fingers) or "how do I delete an entry (in a tableview)" (A: Swipe your finger over the entry from left to right, and press the red delete button).
If I get an email about this I just point them to the faq which has some nice screenshots.
Btw, if the "broken state" happens so often that you would consider adding a special button I would check my code for bugs again.