ios7.1:推送通知徽章更新问题

ios7.1:推送通知徽章更新问题,第1张

概述我在我当前的一个项目中设置了推送通知.我已经按照推送通知所需的所有指令.在[tag:ios7]中正常工作,但在7.1中,当我的应用程序处于后台模式时,我在徽章更新中遇到问题. 我的代码如下: – - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchO 我在我当前的一个项目中设置了推送通知.我已经按照推送通知所需的所有指令.在[tag:ios7]中正常工作,但在7.1中,当我的应用程序处于后台模式时,我在徽章更新中遇到问题.

我的代码如下: –

- (BOol)application:(UIApplication *)application dIDFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ [[UIApplication sharedApplication] registerForRemoteNotificationTypes:     (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];}- (voID)application:(UIApplication*)application dIDFailToRegisterForRemoteNotificationsWithError:(NSError*)error{    NSLog(@"Failed to get token,error: %@",error);}- (voID)application:(UIApplication*)application dIDRegisterForRemoteNotificationsWithDevicetoken:(NSData*)devicetoken{    Nsstring *str = [Nsstring                     stringWithFormat:@"%@",devicetoken];    NSLog(@"%@",str);    self.devicetoken = [Nsstring stringWithFormat:@"%@",str];    NSLog(@"dev --- %@",self.devicetoken);    self.devicetoken = [self.devicetoken stringByReplacingOccurrencesOfString:@"<" withString:@""];    self.devicetoken = [self.devicetoken stringByReplacingOccurrencesOfString:@" " withString:@""];    self.devicetoken = [self.devicetoken stringByReplacingOccurrencesOfString:@">" withString:@""];    NSLog(@"dev --- %@",self.devicetoken);}

并获得回应

-(voID)application:(UIApplication*)application dIDReceiveRemoteNotification:(NSDictionary*)userInfo{    UIApplicationState state = [application applicationState];    // If your app is running    if (state == UIApplicationStateActive)    {        //You need to customize your alert by yourself for this situation. For ex,Nsstring *cancelTitle = @"ok";      //  Nsstring *showTitle = @"Get Photos";        Nsstring *message = [[userInfo valueForKey:@"aps"] valueForKey:@"alert"];        UIAlertVIEw *alertVIEw = [[UIAlertVIEw alloc] initWithTitle:@""                                                            message:message                                                           delegate:self                                                  cancelbuttonTitle:cancelTitle                                                  otherbuttonTitles:nil];        [alertVIEw show];    }    // If your app was in in active state    else if (state == UIApplicationStateInactive)    {    }     [UIApplication sharedApplication].applicationIconBadgeNumber = [UIApplication sharedApplication].applicationIconBadgeNumber + [[[userInfo objectForKey:@"aps"] objectForKey: @"badge"] intValue];}

第一件事是,当我的应用程序回到地面时,dIDReceiveRemoteNotification没有被调用,所以我做了一些搜索并放置: –

- (voID)application:(UIApplication *)applicationdIDReceiveRemoteNotification:(NSDictionary *)userInfofetchCompletionHandler:(voID (^)(UIBackgroundFetchResult))completionHandler

并将背景模式设置为: –

当我的设备连接xcode并运行应用程序测试推送通知但是当我拔掉设备(iOS7.1)时,一切正常.然后推送通知到达但徽章没有更新.否则,徽章会在后台更新,也会调用所有方法.但同样的事情我测试这个应用程序到我的另一台iOS7设备,运行良好.

我无法理解我的错误在哪里以及我在代码中做错了什么.是否有任何错误或我不认为所以请帮助我这个.

解决方法 尝试:

int badge = [UIApplication sharedApplication].applicationIconBadgeNumber;[UIApplication sharedApplication].applicationIconBadgeNumber = 0; // try 0 or -1[UIApplication sharedApplication].applicationIconBadgeNumber = badge + [[[userInfo objectForKey:@"aps"] objectForKey: @"badge"] intValue];
总结

以上是内存溢出为你收集整理的ios7.1:推送通知徽章更新问题全部内容,希望文章能够帮你解决ios7.1:推送通知徽章更新问题所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1023190.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存