从 Python 代码发送 Apple 的推送通知

发布于 2024-12-28 16:27:42 字数 291 浏览 1 评论 0原文

我想从 Python 代码(Django 应用程序)向客户的手机发送推送通知。

我找到了几个实现,其中之一在这里: http://leepa.github.com/django -iphone-push/

我的问题是 - 如何识别我要向其发送通知的设备?我应该使用手机的 UDID 吗?我担心的是它在 iOS5 中已经被弃用,所以我想知道如何将用户与我的 Django 服务器中的手机绑定?

I want to send a push-notification from the Python code (Django app) to client's phones.

I found several implementations, one of them is here: http://leepa.github.com/django-iphone-push/

My question is - how to identify the device for which I'm sending the notification to? Should I use the UDID of the phone? My concern is that it's already deprecated in iOS5, so I'm wondering how to tie the user with the phone in my Django server?

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

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

发布评论

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

评论(2

ま柒月 2025-01-04 16:27:42

Apple 只允许您向安装了 iOS 应用程序且用户允许您的应用程序向其设备发送通知的设备发送通知。您可以在 此开发者文档

如果您没有 iOS 应用程序,但仍想向用户发送通知,可以考虑使用 Prowl、Notifio或棚车。这些应用程序允许您使用其 API 将通知传递到用户设备。对于大多数这些服务,它们都有可用的 Python 包。

Apple only let's you send notification to devices on which your iOS applicaiton is installed and for which the user has allowed your app to deliver notifications to their device. You can find more information on how Apple handles (push) notifications in this developer document.

If you don't have an iOS applications but still want to deliver notifications to users, you can consider to use Prowl, Notifio or Boxcar. These apps allow you to user their API to deliver the notifications to a users device. For most of these services their are Python packges available.

诗酒趁年少 2025-01-04 16:27:42

来自文档:

注意:设备令牌与 UIDevice 的 uniqueIdentifier 属性返回的设备 UDID 不同。

使用的令牌是通过在 application:didFinishLaunchingWithOptions: 中注册远程通知来获取的。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // ...
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
    // ...
}

如果注册成功,您的应用程序委托将收到 application:didRegisterForRemoteNotificationsWithDeviceToken:

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    NSString *deviceTokenStr = [[[[deviceToken description]
                                  stringByReplacingOccurrencesOfString: @"<" withString: @""] 
                                 stringByReplacingOccurrencesOfString: @">" withString: @""] 
                                stringByReplacingOccurrencesOfString: @" " withString: @""];
    NSLog(@"%@", deviceTokenStr);
}

这是您用于发送的令牌推送通知。

PS:django-iphone-push 上次提交是 3 年前。你可以尝试我的分支 django-ios-push

From the docs:

Note: A device token is not the same thing as the device UDID returned by the uniqueIdentifier property of UIDevice.

Token used is acquired by registering for remote notifications in application:didFinishLaunchingWithOptions:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // ...
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
    // ...
}

If registering was successful, your app delegate will receive application:didRegisterForRemoteNotificationsWithDeviceToken:

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    NSString *deviceTokenStr = [[[[deviceToken description]
                                  stringByReplacingOccurrencesOfString: @"<" withString: @""] 
                                 stringByReplacingOccurrencesOfString: @">" withString: @""] 
                                stringByReplacingOccurrencesOfString: @" " withString: @""];
    NSLog(@"%@", deviceTokenStr);
}

This is the token you use to send push notifications.

P.S.: django-iphone-push last commit was 3 years ago. You can try my fork called django-ios-push.

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