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

查看:24
本文介绍了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 一起传递到您的服务器,该用户 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 
}

然后你需要构建你的推送服务器来发送通知,我不会在这里介绍,因为有大量的在线文档,而且非常复杂.您也可以为此使用第三方服务,例如 Urban Airship 和 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天全站免登陆