苹果推送通知-无法回调didRegisterForRemoteNotificationsWithDeviceToken

发布于 2024-08-06 22:11:02 字数 1441 浏览 2 评论 0原文

我只是尝试使用 Apple 推送通知服务从我的 iPhone 应用程序获取 deviceToken。 我暂时在服务器端没有任何实现。 我已经创建了 APP Id,获得了 SSL 证书、带有 APN 的配置文件和调用

- (void)applicationDidFinishLaunching:(UIApplication *)application {
//view init and add sub view to window
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound];
}

方法。 当我执行应用程序时,它会弹出操作框以允许推送通知(意味着我的 APN 注册请求正在运行),但我的回调未执行。 didRegisterForRemoteNotificationsWithDeviceTokendidFailToRegisterForRemoteNotificationsWithError 都没有被调用?有人可以帮我解决这个问题吗?以下是我的回调供参考。

    - (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {

            UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"APNClient" message:@"Entered into Error Method" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [myAlert show];
            [myAlert release];
            NSLog(@"Error in registration. Error: %@", err);

        }
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
    UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"APNClient" message:@"Got the deviceToken..!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [myAlert show];
    [myAlert release];        
}

I have been simply trying to get deviceToken from my iPhone application using Apple Push Notification Service.
I don't have any implementation on server side for the time being.
I have created APP Id, got SSL certificate, Provision Profile with APN and calling

- (void)applicationDidFinishLaunching:(UIApplication *)application {
//view init and add sub view to window
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound];
}

method.
When I execute the application it pop ups action box to allow Push Notification (means my request for APN registration is working) but my callback is not executed. Neither didRegisterForRemoteNotificationsWithDeviceToken nor didFailToRegisterForRemoteNotificationsWithError is called? can anybody help me to resolve the issue? Following are my callbacs for reference.

    - (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {

            UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"APNClient" message:@"Entered into Error Method" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [myAlert show];
            [myAlert release];
            NSLog(@"Error in registration. Error: %@", err);

        }
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
    UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"APNClient" message:@"Got the deviceToken..!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [myAlert show];
    [myAlert release];        
}

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

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

发布评论

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

评论(4

凉世弥音 2024-08-13 22:11:02

该应用程序应该使用:

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

- (void)applicationDidFinishLaunching:(UIApplication *)application

The app should be using:

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

not

- (void)applicationDidFinishLaunching:(UIApplication *)application
赏烟花じ飞满天 2024-08-13 22:11:02

我发现推送通知需要在您的网络中打开端口 5223(如果您使用的是 WIFI),或者蜂窝数据连接。

我在家庭网络中遇到了同样的问题,必须在无线路由器中手动打开端口。

I found out that PUSH notifications require port 5223 open in your network (if you are using WIFI), or otherwise, a cellular data connection.

I encountered the same problem in my home network, and had to open the port manually in the wireless router.

夏天碎花小短裙 2024-08-13 22:11:02

我也遇到过同样的情况,并且花了几个小时试图弄清楚这一点。最终,我认为我的 iPod touch 根本无法连接到 Apple 来获取设备令牌,但这与任何防火墙无关。相反,问题似乎在于建立某种(TLS?)加密连接以及重置为 1970 年某处的设备时钟

更新时间解决了一切。希望这对那里的人有帮助:)。

I've had the same and literally spent hours trying to get to the bottom of this. Ultimately, I figured my iPod touch simply was unable to connect to Apple to get the device token, but it had nothing to do with any firewall. Instead, the problem seemed to be into setting up some kind of (TLS?) encrypted connection in combination with the device's clock that was reset to somewhere 1970.

Updating the time fixed everything. Hope this helps someone out there :).

天冷不及心凉 2024-08-13 22:11:02

回调似乎很好,正如您所说,您应该在(从任何地方)拨打注册电话后不久收到回调。

这似乎是一个愚蠢的问题,但可以肯定的是 - 您的委托方法位于应用程序委托类中吗?

如果是这样,我只是不明白为什么你的方法不会被调用。我在那里看到了 NSLog 语句,但是您是否尝试过在入口处实际设置断点?而且您正在设备上进行测试,而不是模拟器,对吗?

The callbacks seem fine, as you say you should get a callback shortly after making the registration call (from anywhere).

This seems like a dumb question, but just to be sure - you delegate methods are in the application delegate class?

If so, I just can't see why your methods would not be called. I see the NSLog statements there, but have you tried actually setting a breakpoint on entry? And you are testing on the device, not the simulator, right?

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