Question

Okay so I thought of an idea to get around the restraints of my last post (for anyone who read it that is reading this). What I need to do it detect if the application badge number is greater than 0 and then set a boolean depending on if it is greater or not. Here is my code:

Code is no longer relative to the question.

Okay that sets the boolean. Next I read it and execute my actions with this code:

Code is no longer relative to the question.

My only problem is that no matter what the badge number is, it says that the number is 1 AND then doesn't execute my code even if it was 1. Anyone have an idea what I'm doing wrong? Is it the else statements or the way I'm detecting the badge number? Thanks for any help! I'm really stressed about this because this is the only wall I've hit in my app.

Edit: I've fixed my problem and below is the code I used. Please note that this MUST go inside the app delegate.

int badge = application.applicationIconBadgeNumber;
if(badge)
{
    NSLog(@"App Badge is Greater Than 0");
}
    else
{
    NSLog(@"App Badge is Equal To 0");
}
Was it helpful?

Solution 2

Okay, I found the answer to my own question after reading a book on using Cocoa. Here is what I did:

int i = application.applicationIconBadgeNumber;
int y = 0;
NSLog(@"The result is %@", (y<i ? @"True" : @"False"));
if(i)
{
    NSLog(@"App Badge is Greater Than 0");
}
else
{
    NSLog(@"App Badge is Equal To 0");
}

You put that under - (void)applicationDidBecomeActive:(UIApplication *)application. This code compares the app's icon badge and then sees if it is greater than y (0 in my case) and returns a true or false depending on what the badge number is. Hope this helps someone else out!

Edit: Read the post above. It has a much more simple version of this code.

OTHER TIPS

Generally, one uses NSUserDefaults to store values persistently, across invocations of an application. While I'm not sure you actually need to use NSUserDefaults (why not just assign a 'global' variable as Boolean needAutoSMS), if you are using NSUserDefaults perform the following after setting your value:

[[NSUserDefaults standardUserDefaults] synchronize]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top