APNS issue using APNS Sharp - first few notifications undelivered
Here is an issue that is giving me a real headache. We are developing a cross platform application where we need Push Notifications. We have a server syncing every app, and in case the app is not running on one device, we notify the latter if we need to. Push is working fine on the other platform.
The weird thing is that: notifications works well if the app has been opened recently. But after a few hours, the server needs to send at least two notifications (if it's not more) before I can receive one on the device. If the app HAS been opened recently, everything words fine.
The problem can come from:
- The server side. our server API开发者_开发问答 is in C# and we use "APNS Sharp" to send notification to Apple's servers. - Apple's side (not likely i Guess) - The iphone app. But then, why would I receive one from time to time ? I also noticed that sometime, I receive the notification, but then the blue bubble that pops on the screen disappear after a few seconds and even immediately sometimes. Here is a snippet of my code in my App Delegate :- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSLog(@"Registering for remote notifications");
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
return YES;
}
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
NSString * tokenAsString = [[[[devToken description]
stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]]
stringByReplacingOccurrencesOfString:@" " withString:@""] retain];
[self sendToken:tokenAsString];
NSLog(@"enregistré");
}
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
NSLog(@"Error in registration. Error: %@", err);
}
The following function is a function of my own to send the device token to our server. No need to display this.
[self sendToken:tokenAsString];Does anyone have ever heard of such an issue ? Do you think, based on the code snippet that it could come from the app or Apple's servers ? Should we orientate our search more on the server side ?
Thanks a lot.
Pierre
EDIT
Turned out to be a server issue. Apple recommends to keep an open connection to their server to limit the amount of connect/disconnect request. We tried to open one at each time and now it is working properly.
For those who might be interested, this was a server issue. Apple recommends that we keep the connection open to avoid too many connections request.
I'm not really sure how this API works, but we tried to open it once in a while instead (if not for every message) and it works like a charm now. Nothing was wrong in the config on the app above.
Cheers
精彩评论