是否可以从视图控制器请求 APNS 设备令牌?

发布于 2024-12-12 11:48:27 字数 149 浏览 0 评论 0原文

我是 Objective-C 和 iOS 开发的新手,但我想知道是否有一种方法可以从视图控制器请求 Apple 推送通知设备令牌,并将令牌存储在字符串中,以便稍后在发送到我的查询字符串中使用网络应用程序。

我一直在寻找,但未能找到解决此问题的方法。任何帮助将不胜感激!

I'm new to Objective-C and iOS development, but I was wondering if there was a way to request an Apple Push Notification Device Token from the View Controller and store the token in a string to use later in a Query String sent to my web application.

I've been searching, but haven't been able to find a solution to this. Any help would be appreciated!

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

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

发布评论

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

评论(1

逆蝶 2024-12-19 11:48:27

您应该能够在代码中的任何位置调用 registerForRemoteNotificationTypes:

但是您必须在应用程序委托中实现 application:didRegisterForRemoteNotificationsWithDeviceToken:

您最多可以注册 3 种不同类型的通知。只需根据需要删除并添加即可。

[[UIApplication sharedApplication] 
   registerForRemoteNotificationTypes:
   (UIRemoteNotificationTypeAlert |      //Alerts are pop up boxes or on ios5, banners
     UIRemoteNotificationTypeBadge |     //Badges are the little red number on the icon
     UIRemoteNotificationTypeSound)];    //Sounds are... well, sounds. These can be played when presenting a remote notification

You should be able to call registerForRemoteNotificationTypes: anywhere in your code.

But you'll have to implement application:didRegisterForRemoteNotificationsWithDeviceToken: in your app delegate.

You can register for up to 3 different types of notification. Just remove and add as required.

[[UIApplication sharedApplication] 
   registerForRemoteNotificationTypes:
   (UIRemoteNotificationTypeAlert |      //Alerts are pop up boxes or on ios5, banners
     UIRemoteNotificationTypeBadge |     //Badges are the little red number on the icon
     UIRemoteNotificationTypeSound)];    //Sounds are... well, sounds. These can be played when presenting a remote notification
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文