这是我的PHP文件:
if($_POST['message']){ $devicetoken = '(my device token)'; $message = stripslashes($_POST['message']); $payload = '{ "aps" : { "alert" : "'.$message.'","badge" : 1,"sound" : "bingbong.aiff" } }'; $ctx = stream_context_create(); stream_context_set_option($ctx,'ssl','local_cert','cert.pem'); stream_context_set_option($ctx,'passphrase','password'); $fp = stream_socket_clIEnt('ssl://gateway.sandBox.push.apple.com:2195',$err,$errstr,60,STREAM_CLIENT_CONNECT,$ctx); if(!$fp){ print "Failed to connect $err $errstrn"; return; } else { print "DONE!"; } $devArray = array(); $devArray[] = $devicetoken; foreach($devArray as $devicetoken){ $msg = chr(0) . pack("n",32) . pack('H*',str_replace(' ','',$devicetoken)) . pack ("n",strlen($payload)) . $payload; fwrite($fp,$msg); } fclose($fp); }<form action="send-notification.PHP" method="post"> <input type="text" name="message" maxlength="100"> <input type="submit" value="SEND"></form></body>
这就是我在xCode(AppDelegate.m)中所拥有的
- (BOol)application:(UIApplication *)application dIDFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ // OverrIDe point for customization after application launch. [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)]; return YES;}- (voID)application:(UIApplication *)application dIDRegisterForRemoteNotificationsWithDevicetoken:(NSData *)devicetoken{ Nsstring *devicetokenString = [Nsstring stringWithFormat:@"%@",devicetoken]; NSLog(devicetokenString);}解决方法 好吧,我不懂PHP,所以我不能给你具体的代码,但我可以解释一般原理.
当您的应用程序启动时,您应该通过调用registerForRemoteNotificationTypes:方法注册到Apple推送通知.
当注册成功并且您获得设备令牌时,您应该在应用程序的实现中将其发送到您的服务器:dIDRegisterForRemoteNotificationsWithDevicetoken:.
您的服务器应将其存储在某些数据库中.
发送通知的PHP脚本应该从该数据库获取设备令牌.
总结以上是内存溢出为你收集整理的php – 如何获取设备令牌全部内容,希望文章能够帮你解决php – 如何获取设备令牌所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)