Background badging in OS3.0
Hi all,
The method used to badge applications from the command line (Erica Sadun style, with Dynamic Linking to the SBSSpringBoardServerPort) is no longer valid in 3.0. I'm guessing Apple changed it when adding the push-notification service.
Trying to badge an app just ends up with a "Bus Error".
And I can't use the UIApplication +setApplicationIconBadgeNumber: since it's a daemon doing the badging.
Any geniuses out there who have an idea as to what I can try? I'm out of ideas...
Thanks :)
Background badging in OS3.0 [SOLVED]
OK.. I solved it.
Here's what you do:
Use class-dump to dump the headers for /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/System/Library/PrivateFrameworks/iTunesStore.framework/iTunesStore
..OR go to iPhone 3.0 Headers at Erica Sadun's site to get the following 3 class headers:
ISOperation.h
ISOperationProgress.h
ISSetApplicationBadgeOperation.h
You may have to edit ISOperation.h:
1. Change the #import "NSOperation.h" to #import <Foundation/NSOperation.h>
2. Remove the "<ISOperationDelegate>" in the first part of the interface. So you're just left with "id _delegate;"
Then copy these 3 files into a "Headers" dir inside of the /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/System/Library/PrivateFrameworks/iTunesStore.framework dir.
You can now add the iTunesStore framework to your xcode project. Just point to the dir above.
Now add "#import <iTunesStore/ISSetApplicationBadgeOperation.h>" to your code and, for your convenience, here's an example-function ready for use:
Code:
BOOL badge(NSString *bundleIdentifier, NSInteger number)
{
ISSetApplicationBadgeOperation *sbadge = [[ISSetApplicationBadgeOperation alloc] init];
if (sbadge == nil) return FALSE;
[sbadge setBundleIdentifier:bundleIdentifier];
[sbadge setBadgeValue:[NSString stringWithFormat:@"%d",number]];
[sbadge run];
[sbadge release];
return TRUE;
}
Usage: badge(@"com.yourcompany.yourapp",2);
Remove the badge by passing 0 as the number. Sadly it doesn't work with strings..
Do note, that we're using undocumented methods here, so they could change at any point ..which Apple isn't shy to tell us. Let's hope they keep it around for a while.
Cheers and happy coding :)
(Thanks to Steve Nygard for class-dump and Erica Sadun for being such a great source for information. Aaah, free information)