0

我已將遠程通知添加到我的應用程序,但只在應用程序位於前臺時才起作用。當應用程序在後臺運行時,我推動沒有任何反應。執行iOS推送通知的問題

我在的appDelegate代碼如下:

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

    // Override point for customization after application launch. 
    NSLog(@"Registering for push notifications..."); 
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)]; 

    return YES; 
} 


-(void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken 
{ 
    NSString*str =[NSString stringWithFormat:@"Device Token=%@",deviceToken]; 
    NSLog(@"%@",str); 

} 

-(void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError*)err 
{ 
    NSString*str =[NSString stringWithFormat: @"Error: %@", err]; 
    NSLog(@"%@",str); 
} 



- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 
{ 
    NSDictionary *messageBundleReceived = [userInfo objectForKey:@"CLS-Alert"]; 
    NSString *messageReceived = [messageBundleReceived objectForKey:@"alert"]; 

    NSString *badgeNumberReceived = [messageBundleReceived objectForKey:@"badge"]; 

    int badgeNumber = badgeNumberReceived.intValue; 

    UIAlertView *remoteAlert = [[UIAlertView alloc] initWithTitle:@"Attention!!" 
                  message:messageReceived 
                 delegate:self cancelButtonTitle:@"Ok" 
               otherButtonTitles:nil, nil]; 
    [remoteAlert show]; 

    [UIApplication sharedApplication].applicationIconBadgeNumber = badgeNumber; 
} 

我使用PushMeBaby進行推動,並且已經採取了所有的設置照顧等證書,並置備設備的事實證明它在前臺時確實收到推送。每個選項都在通知中心中打開。

有關爲什麼alertView在應用程序位於後臺時未彈出的任何想法?

+0

當應用程序在前臺和你發生了什麼得到推送通知? (因爲我沒有看到任何'alertView'代碼正在被使用)。如果您正在討論推送通知提醒類型,請轉到設置並將應用提醒類型更改爲您想要的 – staticVoidMan

+0

在上面的didReceiveRemoteNotification方法中,我顯示了一個AlertView。我希望在應用程序處於後臺時發生這種情況。 – Scooter

+0

AlertView不會出現,直到用戶將您的應用程序置於前臺(通過單擊通知baner) –

回答