我在當前的一個項目中設置了Push Notification
。我已按照推送通知所需的所有說明進行操作。在[tag:ios7]中工作正常,但在7.1
我在後臺模式下的應用程序中發現了徽章更新問題。ios7.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 *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
並設置背景模式,如: -
,所有工作正常,當我的設備是在Xcode和連接i上運行應用程序測試推送通知但當我拔下設備(iOS7.1)。然後推送通知到達但徽章不更新。否則,在後臺更新徽章以及調用所有方法。但同樣的事情,我測試這個應用程序到我的另一臺設備iOS7
工作得很好。
我不明白我的錯誤在哪裏,而且我在代碼中做錯了。有沒有任何錯誤或我不認爲,所以請幫我解決這個問題。
你的服務器是否在'apn'發送了一個徽章? – cojoj
我正在設置我身邊的徽章,正如我在上述問題中提到的。 –
但是您正在使用遠程通知...它是管理徽章的服務器端,而不是設備上的您。 – cojoj