如何在生产中成功发送 APNS 推送通知
当我在开发中使用时,它的工作。
但是在生产中使用,它会出现错误。
我的应用程序在 App Store 中,所以 p12 文件是生产的。
我的服务器端是asp.net。
asp.net 代码:
//key
//True if you are using sandbox certificate, or false if using production
bool sandbox = false;
string p12File = "InspirePass.p12";
string p12Filename = System.IO.Path.Combine(MapPath("~"), p12File);
string p12FilePassword = "xxxxxxxx";
NotificationService service = new NotificationService(sandbox, p12Filename, p12FilePassword, 1);
//send
foreach (DataRow eachUserRow in userTable.Rows)
{
//Create a new notification to send
if (eachUserRow["pushStatus"].ToString() == "N")
{ //////no repeat
Notification alertNotification = new Notification(eachUserRow["device_token"].ToString());
alertNotification.Payload.Alert.Body = eachUserRow["menuMessage"].ToString() + "(" + eachUserRow["menuTitle"].ToString() + ")";
alertNotification.Payload.Sound = "default";
alertNotification.Payload.Badge = selectEventPush_IOS.Rows.Count + selectSignPush_IOS.Rows.Count;
// alertNotification.Payload. = 1;
string[] items = new string[1];
string[] items2 = new string[1];
if (userTable.Rows.Count > 0)
{
items[0] = Convert.ToString(selectEventPush_IOS.Rows.Count);
items2[0] = Convert.ToString(selectSignPush_IOS.Rows.Count);
}
alertNotification.Payload.CustomItems.Add("items2", items2);
alertNotification.Payload.CustomItems.Add("items", items);
//Queue the notification to be sent
if (service.QueueNotification(alertNotification))
result = 1;
else
result = -1;
///////change chat_document/pushStatus=Y
string Identifier = "";
Identifier = eachUserRow["Identifier"].ToString();
DataRow yespushuser = DBiphone.UpdatedPushStatus(Identifier);
}
}//end if
service.Close();
service.Dispose();
Response.Write(result.ToString());