0
在安裝應用程序後的iPhone/iPad上,應用程序能夠首次接收通知。一旦應用程序處於不活動狀態,它就會停止在前臺和後臺獲取通知。當應用程序在一天內未處於活動狀態時,GCM推送通知不會在iPhone上顯示
有人可以指出,我是我失蹤。從我第一次來看,看起來沒有消息格式的問題。
服務器代碼:
message.put("priority", "high");
message.put("content_available",true);
if (to != null)
{
message.put("to", to.replace("\\", ""));
}
if (messageId != null)
{
message.put("message_id", messageId);
}
JSONObject subobj = new JSONObject();
subobj.put("sound", "default");
message.put("notification", subobj);
message.put("data", payload);
if (timeToLive != null)
{
message.put("time_to_live", timeToLive);
}
if (delayWhileIdle != null && delayWhileIdle)
{
message.put("delay_while_idle", true);
}
if (collapseKey != null)
{
message.put("collapse_key", collapseKey);
}
message.put("delivery_receipt_requested", true);
客戶端代碼:
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
// First run Delete keychain
if (![[NSUserDefaults standardUserDefaults] objectForKey:@"FirstRun"]) {
// Delete values from keychain here
application.applicationIconBadgeNumber = 0;
[self resetKeychain];
[[NSUserDefaults standardUserDefaults] setValue:@"1strun" forKey:@"FirstRun"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
self.viewController = [[MainViewController alloc] init];
CGRect screenBounds = [[UIScreen mainScreen] bounds];
#if __has_feature(objc_arc)
self.window = [[UIWindow alloc] initWithFrame:screenBounds];
#else
self.window = [[[UIWindow alloc] initWithFrame:screenBounds]
autorelease];
#endif
self.window.autoresizesSubviews = YES;
//notification
[self updateDurationLabel];
UIFont *font = [UIFont boldSystemFontOfSize:10.0f];
NSDictionary *attributes = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
[self.segFromStyle setTitleTextAttributes:attributes forState:UIControlStateNormal];
[self.segToStyle setTitleTextAttributes:attributes forState:UIControlStateNormal];
[self flowManager];
UILocalNotification *remoteNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (remoteNotification) {
application.applicationIconBadgeNumber = 0;
self.launchNotification = remoteNotification.userInfo;
NSLog(@"NotificationCheck: remoteNotification");
}
UILocalNotification *localNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotification) {
application.applicationIconBadgeNumber = 0;
NSLog(@"NotificationCheck: localNotification");
self.launchNotification = localNotification.userInfo;
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:localNotification.userInfo options:0 error:nil];
NSString* jsonString = [[NSString alloc] initWithBytes:[jsonData bytes] length:[jsonData length] encoding:NSUTF8StringEncoding];
NSLog(@"Dict:%@", jsonString);
}
[self.window makeKeyAndVisible];
return YES;
}
感謝響應。我確實已經設置了優先級和content_available標誌。 [message.put(「priority」,「high」); message.put(「content_available」,true);]只有在代碼中丟失的標誌是'徽章',讓我試試它的運氣。 – leela