简体   繁体   English

iPhone推送通知

[英]iPhone Push Notifications

I have a iPhone app that uses Push Notifications. 我有一个使用推送通知的iPhone应用程序。 My understanding of how this works is I need the "Device Token" of each iPhone before I can send a notification. 我对此的理解是,在发送通知之前,我需要每个iPhone的“设备令牌”。

Using the test iPhones I have, I can obtain the Device Token from the xcode interface and store them in a data table which the Push Notification PHP script uses to send the notifications. 使用我拥有的测试iPhone,我可以从xcode接口获取设备令牌,并将它们存储在数据表中,Push Notification PHP脚本用来发送通知。

How do I send the Push Notifications to iPhones that install the app of which I do not know the Device Token ID. 如何将推送通知发送到安装了我不知道设备令牌ID的应用的iPhone。

I think my question is; 我想我的问题是; do I need the Device Tokens before I can sent a notification to a iPhone. 在向iPhone发送通知之前,我需要设备令牌吗?

If I do require the Device Token, how do I obtain it from iPhones using my app. 如果我确实需要设备令牌,如何使用我的应用程序从iPhone获得它。

You can't receive any Push Notification with the Simulator. 您无法通过模拟器收到任何推送通知。

You don't directly send a notification. 您不会直接发送通知。 You said to Apple's servers that there is a notification for this Device Token. 您对Apple的服务器说,此设备令牌有一个通知。 Then iPhones themselves will ask automatically to receive push notifications is some are available. 然后,iPhone本身会自动要求接收推送通知(如果有的话)。

To answer to your question : Yes you do. 要回答您的问题:是的。 Without the Device Token you can't register your notification to Apple's server. 没有设备令牌,您将无法将通知注册到Apple的服务器。 Then you have to implement this register the device to get the DeviceToken: 然后,您必须对该设备实施此注册以获得DeviceToken:

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken

Here is you should look up == Push Notification Programming Guide 您应该在这里查找== 推送通知编程指南

- (void)applicationDidFinishLaunching:(UIApplication *)app {
   // other setup tasks here....
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
}

// Delegation methods
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
    const void *devTokenBytes = [devToken bytes];
    self.registered = YES;
    [self sendProviderDeviceToken:devTokenBytes]; // custom method
}

- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
    NSLog(@"Error in registration. Error: %@", err);
}

See the code from apple Local and Push Notification Programming Guide , first you have to call registerForRemoteNotificationTypes in your app, and then in two delegates, you can get dev token or not, this token is from APNS, so when you get it, you will send it to your service to store it. 请参阅apple Local和Push Notification编程指南中的代码,首先必须在应用程序中调用registerForRemoteNotificationTypes,然后在两个委托中,可以获取或不获取dev令牌,此令牌来自APNS,因此,一旦获取,您将将其发送到您的服务以进行存储。 And you can't get a device token from simulator. 而且您无法从模拟器获得设备令牌。

Your push notification service will have to use the device token to send notification to your app, so you will definitely need it. 您的推送通知服务将必须使用设备令牌将通知发送到您的应用,因此您肯定需要它。 In additional, you will have to get SSL certificates from apple dev center, that requires an valid paid developer ID of iOS. 此外,您还必须从Apple开发中心获取SSL证书,该证书需要有效的iOS付费开发人员ID。

For more information, please check Push Notification Programming Guide , and it's a great help. 有关更多信息,请查看“ 推送通知编程指南” ,它是一个很大的帮助。 Furthermore, I tried this PHP library to test push notification service, and it's good, you can just find its unit test, and paste the device token there, and run it, you will get message from it. 此外,我尝试了这个PHP库来测试推送通知服务,这很好,您可以找到它的单元测试,然后将设备令牌粘贴到其中,然后运行它,您将获得消息。

sly/notification-pusher 狡猾/通知推送

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM