2015-11-05 137 views
2

我試圖設置我的應用程序以接收來自GCM的推送通知。當應用程序在前臺運行在AppDelegate中的方法調用:當應用程序在後臺時不顯示推送通知

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler 
{ 
DLog(@"Notification received: %@", userInfo); 
// This works only if the app started the GCM service 
[[GCMService sharedInstance] appDidReceiveMessage:userInfo]; 

completionHandler(UIBackgroundFetchResultNoData); 
} 

示例日誌是這樣的:

Notification received: { 
aps =  { 
    alert = "myk myk"; 
    badge = 2; 
    sound = default; 
    }; 
"gcm.message_id" = "0:1446730003823773%cc4efdeacc4efdea"; 
} 

的問題是,當我的應用程序是在後臺有在沒有信息所有人都在通知中心,沒有警告/橫幅正在顯示。我檢查了設置 - >通知和通知爲我的應用程序啓用。當我進入我在後臺的應用程序時,我有關於通知的信息,但這不是我想要的。

我使用iOS 9.0.1和xCode 7.1 爲什麼當我的應用程序在後臺時沒有通知橫幅?

+0

當你的應用程序在後臺didFinishLaunchingWithOptions開始實施時,在那裏顯示你的代碼......你是否解決了這個問題? – XcodeNOOB

回答

0

比較例如您的有效載荷從蘋果網站

{ 
"aps" : { 
    "alert" : { 
     "title" : "Game Request", 
     "body" : "Bob wants to play poker", 
     "action-loc-key" : "PLAY" 
    }, 
    "badge" : 5 
}, 
"acme1" : "bar", 
"acme2" : [ "bang", "whiz" ] 
} 

警報JSON可能是錯誤的。

相關問題