[英]How Do We Receive a Notification from Server When there is a Update in the Database in ios
I Am New to Notifications in iOS. 我是iOS通知的新手。 My Task is to Receive Notifications from Server to My Application Whenever there is an Update in the Database.
我的任务是每当数据库中有更新时,接收从服务器到我的应用程序的通知。
I Searched for this one and I have Implemented Location Notification in iOS. 我搜索了此文件,并在iOS中实现了位置通知。
Can Some One Give me some steps for Receiving Notifications from Server? 有人可以给我一些步骤来接收来自服务器的通知吗?
1) you have to make code from your server side(using .net or php etc) to push the notification to APNS as per your criteria. 1)您必须根据自己的标准从服务器端编写代码(使用.net或php等),以将通知推送到APNS。
for push notification you need following: 对于推送通知,您需要执行以下操作:
- Device token for in which phone you want to receive notification.
您要在其中接收通知的电话的设备令牌。
- p12 file of your push notification certificate from developer.apple.com site which you generated for your particular app ( you can export p12 file from keychain by selecting your particular app push notification certificate)
您为特定应用生成的来自developer.apple.com网站的推送通知证书的p12文件(您可以通过选择特定应用的推送通知证书从钥匙串中导出p12文件)
2) Enable your app to receive pushnotification using below: 2)使用以下方法启用您的应用程序以接收推送通知:
-(BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
[[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeSound |UIRemoteNotificationTypeAlert)];
return YES;
}
3) now following method will receive push notification from your xcode when push notification aries; 3)现在以下方法将在推送通知白羊座时从您的xcode接收推送通知;
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo { ...}
this is general scenario for pushnotification for brief description read following : 这是用于pushnotification的一般情况,以进行简要说明,请阅读以下内容:
I'm assuming you are talking about your remote database, in which case you have to implement a push notification. 我假设您正在谈论远程数据库,在这种情况下,您必须实现推送通知。
The tutorial on raywenderlich.com is bit lengthy on this subject, but covers everything you need to do, both on the app side and the server side. raywenderlich.com上的教程对此主题有些冗长,但是涵盖了您需要做的所有事情,包括应用程序端和服务器端。
Link: http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1 链接: http : //www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1
Write a php/python script for that and put it into your web server.here a php script sample save it with example.php and put it into your server with .pem(private key) file also replace your device token with that device token in which you want sent notification. 为此编写一个php / python脚本并将其放入您的Web服务器中。此处的一个php脚本示例将其与example.php保存在一起,并使用.pem(私有密钥)文件将其放入您的服务器中,并用该设备令牌替换您的设备令牌您要在其中发送通知的位置。
<?php
// Put your device token here (without spaces):
$deviceToken = '0f744707bebcf74f9b7c25d48e3358945f6aa01da5ddb387462c7eaf61bbad78';
// Put your private key's passphrase here:
$passphrase = 'pushchat';
// Put your alert message here:
$message = 'My first push notification!';
////////////////////////////////////////////////////////////////////////////////
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
// Open a connection to the APNS server
$fp = stream_socket_client(
'ssl://gateway.sandbox.push.apple.com:2195', $err,
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if (!$fp)
exit("Failed to connect: $err $errstr" . PHP_EOL);
echo 'Connected to APNS' . PHP_EOL;
// Create the payload body
$body['aps'] = array(
'alert' => $message,
'sound' => 'default'
);
// Encode the payload as JSON
$payload = json_encode($body);
// Build the binary notification
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));
if (!$result)
echo 'Message not delivered' . PHP_EOL;
else
echo 'Message successfully delivered' . PHP_EOL;
// Close the connection to the server
fclose($fp);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.