IOS推送通知给特定的用户? [英] IOS Push Notifications to specific users?

查看:248
本文介绍了IOS推送通知给特定的用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以在iOS推送通知发送到特定设备?我已经建立了一个论坛类型的应用程序,用户可以创建一个问题,其他人可以回答。我需要在iOS推送通知发送到该问的问题,告知他们该问题得到回答特定的用户。这是可能通过PHP或其它方法来实现?

Is possible to send an iOS push notification to a specific device? I've built a forum type app which the user can create a question and other people can answer it. I need to send an iOS Push Notification to the specific user which asked the question informing them that the question was answered. Is this possible to be done through PHP or another method?

推荐答案

是的,你绝对可以发送推送通知到一个特定的设备。

Yes, you can absolutely send a push notification to a specific device.

首先,你需要询问设备是否允许接收推送通知:

First you need to ask the device for permission to receive push notifications:

[[UIApplication sharedApplication]
 registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
                                     UIRemoteNotificationTypeSound |
                                     UIRemoteNotificationTypeAlert)]; 

这时如果用户接受,您将收到委托消息didRegisterForRemoteNotificationsWithDeviceToken。然后,您传递deviceToken到您的服务器与您的应用程序识别到你的论坛用户的用户ID。事情是这样的:

Then if the user accepts you will receive the delegate message didRegisterForRemoteNotificationsWithDeviceToken. You then pass that deviceToken to your server with the user Id from your app that identifies the user in your forum. Something like this:

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)_deviceToken {

    NSString* deviceToken = [[[[_deviceToken description]
                            stringByReplacingOccurrencesOfString: @"<" withString: @""] 
                            stringByReplacingOccurrencesOfString: @">" withString: @""] 
                            stringByReplacingOccurrencesOfString: @" " withString: @""];

   //send deviceToken and your userId to your server to associate the two together 
}

然后,你需要建立它发送通知,我不会进入这里因为有一吨的文档在线的,这是相当复杂的推送服务器。您也可以为这个如城市飞艇和StackMob使用第三方服务。

Then you need to build your push server which sends the notifications, which I won't get into here as there is a ton of documentation online for that and it is quite involved. You can also use third party services for this such as Urban Airship and StackMob.

这篇关于IOS推送通知给特定的用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆