English 中文(简体)
设置套件应用IconBadge 数字无效果
原标题:setApplicationIconBadgeNumber not having any effect
  • 时间:2012-05-24 22:26:03
  •  标签:
  • ios

我正在试验从通知中心清除通知(其中变通办法包括将徽章编号设定为0,因为没有pi可去除)。

然而,在实验中,我注意到,我不能获得SetApplicationIconBadgenumber 来对徽章号码产生任何影响。

例如,如果我有:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{    
      [[UIApplication sharedApplication] setApplicationIconBadgeNumber: 5];

(和设置应用IconBadge number 没有在别处被调用)

那么图标就没有徽章,更不用说包含数字的徽章了。

(通知没有设定徽章号码, 也许在设定 ApplicationIconBadge number 之前必须先设定徽章号码: 有任何效果, 有人能确认或否认吗? )

我注意到这个在控制台里, 可能与此有关:

May 24 16:12:49 unknown installd[138] <Error>: entitlement  aps-environment  has value not permitted by a provisioning profile
May 24 16:12:49 unknown SpringBoard[51] <Warning>: Killing com.mycompany.xxx for termination assertion
May 24 16:12:50 unknown installd[138] <Error>: entitlement  aps-environment  has value not permitted by a provisioning profile
May 24 16:12:50 unknown SpringBoard[51] <Warning>: Reloading application state for  com.mycompany.xxx  as its modification date or path has changed
May 24 16:12:50 unknown SpringBoard[51] <Warning>: Reloading and rendering all application icons.

最后一行听起来具有关联性, 这才刚刚开始发生, 不知道原因, 我还没有修改过配置等等, 它们在 Xcode 中是最新和有效的。 我将为此另选一个问题

问题回答

如果您在 iOS8 + 不工作 iOS8 上再次出现问题 setApplicationIconBadgenumber , 因为从 iOS8 开始的本地通知必须请用户允许 :

UIUserNotificationType userNotificationTypes = UIUserNotificationTypeBadge;
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes categories:nil];
[application registerUserNotificationSettings:settings];

我也有这个问题

在测试你的设备时,下面的线是正确的电话:

[[[UIApplication 共享应用] 成套应用IconBadge 编号: 5];

它在哪里被调用 虽然这很重要。如果你只叫它进来:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

它只有在应用程序完全关闭时才执行。 测试时, 因为您经常进出, 应用程序只能输入背景并被暂停, 这样一来, 程序也可以调用它 :

- (void)applicationDidBecomeActive:(UIApplication *)application 

希望这有帮助。

你可能会尝试加注 和减少 徽章一一一个一个。

[UIApplication sharedApplication].applicationIconBadgeNumber++;    

不过,我怀疑你的问题更多 是你的程序何时到达代码线的问题

希望这能帮上忙

我刚刚发现一定是数字 & gt; 0。 负数无效 。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签