使用 APNS Sharp 的 APNS 问题 - 前几个通知未送达

发布于 2024-12-02 11:02:54 字数 1674 浏览 1 评论 0原文

这是一个让我非常头疼的问题。我们正在开发一个需要推送通知的跨平台应用程序。我们有一台同步每个应用程序的服务器,如果该应用程序未在一台设备上运行,我们会在需要时通知后者。推送在其他平台上运行良好。

奇怪的是:如果最近打开过应用程序,通知效果很好。但几个小时后,服务器需要发送至少两个通知(如果不是更多),然后我才能在设备上收到通知。如果最近打开过该应用程序,一切都很好。

问题可能来自:
- 服务器端。我们的服务器 API 采用 C# 编写,我们使用“APNS Sharp”向 Apple 的服务器发送通知。
- 苹果这边(我猜不太可能)
- iPhone 应用程序。但是,为什么我会时不时地收到一份呢?我还注意到,有时,我收到通知,但屏幕上弹出的蓝色气泡会在几秒钟后消失,有时甚至立即消失。 这是我的应用程序委托中的代码片段:

- (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);
}

以下函数是我自己的函数,用于将设备令牌发送到我们的服务器。无需显示此内容。
[自我发送令牌:tokenAsString];

有人听说过这样的问题吗?根据代码片段,您认为它可能来自应用程序或 Apple 的服务器吗?我们应该更多地将搜索定位在服务器端吗?

多谢。

皮埃尔

编辑

原来是服务器问题。 Apple 建议保持与其服务器的开放连接,以限制连接/断开连接请求的数量。我们每次都尝试打开一个,现在它可以正常工作。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暗地喜欢 2024-12-09 11:02:54

对于那些可能感兴趣的人来说,这是一个服务器问题。苹果建议我们保持连接打开以避免过多的连接请求。

我不太确定这个 API 是如何工作的,但我们尝试偶尔打开它(如果不是每条消息),现在它的工作方式就像一个魅力。上面的应用程序的配置没有任何问题。

干杯

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文