Why the applicationIconBadgeNumber is not getting deleted with appliccation ? Where it stored actually? [duplicate] - iphone

I'm setting my applicationIconBadgeNumber using this code:
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:theIntToDisplay];
The problem is that when I delete the app from an iPad and reinstall it, the app icon still shows the previous badge number. Is this default iOS behavior or can we reset it?
I found one similar question on at Why the applicationIconBadgeNumber is not getting deleted with appliccation ? Where it stored actually?, but it didn't answer my question.

This is an expected behavior, the badge number remains for a short period after uninstall e.g for the case of an immediate re-install.
Of course you can nullify badge number after every launching the application in application:didFinishLaunchingWithOptions: method but I think it is not the case because you want badge number not to be shown right after you install app and not yet launch it. In such a case just wait after removing the application and the badge numbers cache will be cleared by iOS and then install the app again. Unfortunately without jailbreaking the device there is no way to manage badge numbers behavior manually

In your app delegate under:
- (void)applicationWillEnterForeground:(UIApplication *)application
{
}
Insert:
application.applicationIconBadgeNumber = 0;

Related

How to simulate the very first start of an app in Xcode 6

I need to test some behaviors of the iOS 8 at the very first start of my app. Is it possible to simulate this in Xcode 6? If yes, then how?
Deleting the app will do it but note that certain pieces of information will be cached for a while like your permissions settings (notification, calendar, etc.). You can go to settings.app and reset settings to clear those out if that matters in your use case.
If you mean the FIRST start of the app, then what I did to achive this is, on start (viewDidLoad) check in the NSUserDefaults for example ,if the value "hasAlreadyStarted" exists (NSUserDefaults.objectForKey(..) ), if not, then its the first start of the app, and then i would set the value to true, so when you close the app, and open again, the value will exist.
Dareon I'm not sure what exactly you want to achieve. In Xcode 6 yes you can simulate your app from start. If you want to test behaviours I think you are looking for instruments. Right Click on the Xcode icon in your dock select option and choose instruments. You can add several instruments your phone or emulator support like connectivity or gps or memory to see exactly the behaviour of your app. Hope that helps
Well if by very start of the app cycle you mean before the app loads, there is a way.
In your ViewController call the ViewWillLoad function:
class ViewController
{
override func viewWillAppear(animated: Bool)
{
// your code
}
}
This event will be called before the view loads or appears.
Hope it helps :)
As Shanti K said in the comment, if you delete your application from the simulator and then run it again, you will be simulating the first run. To delete the application from the simulator, you mimic the same behavior on a device.
Click and hold on the icon, until they start shaking. Click the close X next to your application, and verify that you want to delete it if it asks. Then Shift + Command + H to simulate hitting the home button.

Clear Application's badge Number

I have made local notification in iphone app. And set icon badge number.
All works good. But if i have two notification in tray and user clicks on clear button than notification deletes from tray.
But the badge number of icon remains same.
I want to set the badge number to zero.
Thanks.
use this in application didfinshlaunchingwithoptions
application.applicationIconBadgeNumber = 0;
For Swift3, you can clear badge number in your application didFinishLaunchingWithOptions with this line :
UIApplication.shared.applicationIconBadgeNumber = 0
You can used this line in anywhere in code if you want too.
What you want to achieve is only possible using the Server Notifications. You can not set badge number locally without opening the application. As you won't have any control when user clears the tray. There's no way you can set the badge count at that moment.

iPhone: What is the correct way to leave an Application?

Hallo Everyone,
with the iOS 4, the iPhone is supporting Multitasking, what is very nice, but something I do not wish to support in my Application. I mean, when the user press the Home-button, I want my application to finish and not to enter in Background. With the iOS 4, when the User press the Home-button, the App calls the applicationDidEnterBackground: delegate's method to enter in Background and in order to "force" the Application to finish when the user press the Home button, I've done following implementation:
- (void)applicationDidEnterBackground:(UIApplication *)application {
//save everything...
exit(0);
}
PROBLEM: I've noticed, that exit(0) brings the Application immediately to finish, without calling deallocating methods like "dealloc", and I think that is not a good programming style. So I would like to ask you guys, how to bring the application to finish in a "nicer" way.
Thanks in advance.
What you actually want is not to exit the application (which is as mentioned not allowed), but tell the OS you would rather your application be killed rather than backgrounded.
There is an info.plist key for that, UIApplicationExitsOnSuspend. Set that in your info.plist to TRUE (checked) and then when your app enters the background it will be terminated.
That's two questions:
How to programmatically exit an iPhone app - duplicate
Proper way to exit iPhone application?
How to cause an iPhone app to not go to background in iOS4:
Add the UIApplicationExitsOnSuspend key to your info.plist and set its value to YES
http://developer.apple.com/iphone/library/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW23
One answer above says "There is an info.plist key for that, UIApplicationExitsOnSuspend. Set that in your info.plist to TRUE (checked) and then when your app enters the background it will be terminated." with Xcode 4, the info.plist value is "Application does not run in background" of type Boolean, so setting this to YES will have the app exit when the user presses the "home" button.
You are not allowed to. I know from experience: got an app rejection from Apple because I've exited (that was two and a half years ago but I doubt they've changed their policy here). There's a "private" (i.e. not mentioned in header file) method "terminate" on UIApplication, IIRC. But Apple says you may not do that. Only thing you can do is to show a dialog, asking the user to press the home button. But in turn doesn't work if on a device with multitasking enabled... so I guess you really have to change your application in such a way that you can throw away your state on applicationDidEnterBackground and start afresh on application on applicationDidBecomeActive.

Reinitializing iPhone app when it relaunches

I am building an iPhone app. Currently when I close the app and relaunch it, it relaunches on the last viewed view. Instead I want to be able to reinitialize the app, and present the view that's most appropriate for the application's state (based on what's in the database).
How can I do that?
You have two options. You can follow Petesh's suggestion to make your app always terminate, or you can implement -applicationWillEnterForeground in your app delegate and reset things there.
I presume it's iOS4 - your app is not being terminated in this case, it is merely being suspended.
You need to follow the instructions here: http://maniacdev.com/2010/07/screw-multi-tasking-how-to-make-your-ios-4-apps-exit-for-real/ which will terminate the app when the user presses the home button.
You need to add the appropriate 'correct view' logic to your application's start-up code once you've done this.
For the purposes of expediency, I'm adding the instructions here:
Open your info.plist file
Add The Key UIApplicationExitsOnSuspend or Select Application does not run in background
Set the new key to YES or Fill in the tick box

Why is the Status Bar STILL showing during Default.png?

I'm pretty sure that I've taken all steps to correctly set my status bar to hidden. I did this in both the info.plist file (setting a UIStatusBarHidden to a boolean TRUE) as well as in the applicationDidFinishLaunching method in the Application Delegate using:
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];
And the status bar does hide -- only not quick enough. Despite the steps taken above, when the app is launched, the status bar is STILL being displayed for about a second during the displaying of the Default.png default image. This looks tacky, and I want to make sure the status bar does not get displayed at any time during the running of the app.
Many apps I've tried ARE hiding the status bar successfully (doesn't even show during the display of default.png) but I can't figure out how. Anyone deal with this issue before?
Did you figure this out already? What I did to get it to work is edit the Info.plist file in TextMate rather than in Xcode. I added the following two lines:
<key>UIStatusBarHidden</key>
<true/>
I think the only thing different from the answers given above is that I used a text editor rather than Xcode. When you subsequently look at Info.plist in Xcode, you will see a check mark next to UIStatusBarHidden rather than a string. There is probably a way to do this directly in Xcode, but I don't know what it is.
UIStatusBarHidden should be set to true.
in the info.plist there's also a key called "Status bar is initially hidden" that needs to be checked on. It will hide the status bar while loading the default.png
It's easier than that. At least in Xcode 4 you can simply add an entry "Status bar is initially hidden" to the plist and set its value to YES.
I was seeing a similar problem on an iPod Touch 2G (3.1.3), where a black rectangle - same dimensions as the status bar - was showing above the default.png.
The solution to this problem involved making the default.png image 320x480 as opposed to its original 640x960. The exact solution was to make a default#2x.png using the larger dimensions.
I have seen this on Jailbroken devices using IOS 2.1 with an older version of Cydia. In that instance, once Cydia was updated, the info.plist + ...statusBarHidden = YES method worked.
Alternatively see if [application setStatusBarStyle: ...] helps.
-isdi-