我有一个iOS应用程序,我想集成推送通知.我见过
tutorial on youtube,一切都还可以,但最近我使用的是开发证书(用于测试 – 不用于AppStore),我的服务器上有PHP脚本.在这个文件中存储了deviceToken,它有我的iPhone并且用PHP变量$deviceToken编写.但是现在,当我想在AppStore中使用它时,如何从已下载我的应用程序并将其加入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); }