菜鸟教程小白 发表于 2022-12-12 08:53:20

ios - 当我的应用程序未激活时,PushNotification 角标(Badge)编号未显示?


                                            <p><p>我在我的应用程序中为 APNS 使用 <code>Urbanairship</code>,一切顺利,但当我的应用程序未运行时,应用程序角标(Badge)编号未显示,但是当应用程序处于事件状态并收到推送时,角标(Badge)编号显示在应用图标上方。</p>

<p>我的代码如下:</p>

<pre><code>   - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
   UAConfig *config = ;
      ;
      // Request a custom set of notification types
      .notificationTypes = (UIRemoteNotificationTypeBadge |
                                             UIRemoteNotificationTypeSound |
                                             UIRemoteNotificationTypeAlert |
                                             UIRemoteNotificationTypeNewsstandContentAvailability);

      return YES;
    }
    - (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {

      NSString *str = ;
      NSLog(@&#34;%@&#34;,str);

    }

    - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
      NSLog(@&#34;Received notification: %@&#34;, userInfo);
      //;

      NSString* alertValue = [ valueForKey:@&#34;badge&#34;];
      NSLog(@&#34;my message-- %@&#34;,alertValue);
      int badgeValue= ;

      [ setApplicationIconBadgeNumber:badgeValue];


    }
- (void)applicationDidBecomeActive:(UIApplication *)application {

    application.applicationIconBadgeNumber = 0;
}
</code></pre>

<p><strong>编辑:</strong>我也试过 -</p>

<pre><code>- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    NSInteger badgeNumber = ;
    ;
}
</code></pre>

<p>但仍然没有运气,我做错了什么?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我遇到了同样的问题,来自 <a href="https://stackoverflow.com/questions/11317701/apple-push-notification-not-changing-icon-badge-automatically" rel="noreferrer noopener nofollow">this question</a> </p>

<p>如果您还注册了 <code>UIRemoteNotificationTypeNewsstandContentAvailability</code>,则将其删除并重试。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 当我的应用程序未激活时,PushNotification 角标(Badge)编号未显示?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/22601649/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/22601649/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 当我的应用程序未激活时,PushNotification 角标(Badge)编号未显示?