我们正在为 iOS 设备开发 MDM 解决方案。
我们已经能够在网站上安装带有 MDM-Payload 的配置文件,并且我们已经收到了由 iOS 设备发送的 PUT 请求,其中还包含 PushMagic、deviceToken 和其他值。
我们使用以下描述创建了 COMPANY.pem SSL 证书:http: //www.softhinker.com/in-the-news/iosmdmvendorcsrsigning
我们尝试使用库 push-sharp 发送推送通知: https ://github.com/Redth/PushSharp
我们使用这些命令构建 MDM.p12 文件
openssl pkcs12 -export -in ./COMPANY.pem -inkey ./customerPrivateKey.pem -certfile ./CertificateSigningRequest.certSigningRequest -out MDM.p12
发送此通知的程序不会抛出任何错误并正常退出。但是我们没有在我们的设备上收到任何推送通知,也没有通过反馈服务收到任何内容。
另外值得一提的是,我们也尝试使用沙盒服务器和生产服务器。
这是我们使用 push-sharp 库的代码:
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Text;
using PushSharp;
using PushSharp.Apple;
namespace PushSharp.Sample
{
class Program
{
static void Main(string[] args)
{
//Create our service
PushService push = new PushService();
//Wire up the events
push.Events.OnDeviceSubscriptionExpired += new Common.ChannelEvents.DeviceSubscriptionExpired(Events_OnDeviceSubscriptionExpired);
push.Events.OnDeviceSubscriptionIdChanged += new Common.ChannelEvents.DeviceSubscriptionIdChanged(Events_OnDeviceSubscriptionIdChanged);
push.Events.OnChannelException += new Common.ChannelEvents.ChannelExceptionDelegate(Events_OnChannelException);
push.Events.OnNotificationSendFailure += new Common.ChannelEvents.NotificationSendFailureDelegate(Events_OnNotificationSendFailure);
push.Events.OnNotificationSent += new Common.ChannelEvents.NotificationSentDelegate(Events_OnNotificationSent);
//Configure and start Apple APNS
// IMPORTANT: Make sure you use the right Push certificate. Apple allows you to generate one for connecting to Sandbox,
// and one for connecting to Production. You must use the right one, to match the provisioning profile you build your
// app with!
//var appleCert = File.ReadAllBytes("C:\\TEMP\\apns-mdm.p12");
var appleCert = File.ReadAllBytes(@".\MDM.p12");
//IMPORTANT: If you are using a Development provisioning Profile, you must use the Sandbox push notification server
// (so you would leave the first arg in the ctor of ApplePushChannelSettings as 'false')
// If you are using an AdHoc or AppStore provisioning profile, you must use the Production push notification server
// (so you would change the first arg in the ctor of ApplePushChannelSettings to 'true')
push.StartApplePushService(new ApplePushChannelSettings(true, appleCert, "PWD"));
//String p12File = @".\apns-mdm.p12";
//String p12Password = "PWD";
String pushMagicString = "00454668-00B2-4122-A1DC-72ACD64E6AFB";
//String deviceToken = "27asObngxvVNb3RvRMs3XVaEWC1DNa3TjFE12stKsig=";
//Configure and start Android GCM
//IMPORTANT: The SENDER_ID is your Google API Console App Project ID.
// Be sure to get the right Project ID from your Google APIs Console. It's not the named project ID that appears in the Overview,
// but instead the numeric project id in the url: eg: https://code.google.com/apis/console/?pli=1#project:785671162406:overview
// where 785671162406 is the project id, which is the SENDER_ID to use!
//push.StartGoogleCloudMessagingPushService(new GcmPushChannelSettings("785671162406", "AIzaSyC2PZNXQDVaUpZGmtsF_Vp8tHtIABVjazI", "com.pushsharp.test"));
//Configure and start Windows Phone Notifications
//push.StartWindowsPhonePushService(new WindowsPhone.WindowsPhonePushChannelSettings());
//Fluent construction of a Windows Phone Toast notification
//push.QueueNotification(NotificationFactory.WindowsPhone().Toast()
//.ForEndpointUri(new Uri("http://sn1.notify.live.net/throttledthirdparty/01.00/AAFCoNoCXidwRpn5NOxvwSxPAgAAAAADAgAAAAQUZm52OkJCMjg1QTg1QkZDMkUxREQ"))
//.ForOSVersion(WindowsPhone.WindowsPhoneDeviceOSVersion.MangoSevenPointFive)
//.WithBatchingInterval(WindowsPhone.BatchingInterval.Immediate)
//.WithNavigatePath("/MainPage.xaml")
//.WithText1("PushSharp")
//.WithText2("This is a Toast"));
//Fluent construction of an iOS notification
//IMPORTANT: For iOS you MUST MUST MUST use your own DeviceToken here that gets generated within your iOS app itself when the Application Delegate
// for registered for remote notifications is called, and the device token is passed back to you
String test = "3d 58 64 4d 90 d3 18 09 22 5c 50 d2 12 16 b5 67 71 1e be 5c 13 6e 41 3c 3e 81 b5 52 30 68 09 a5";
test = test.Replace(" ", string.Empty);
Console.WriteLine("Device Token length is: " + test.Length);
Console.WriteLine("DeviceToken is: " + test);
Console.WriteLine("PushMagic is: " + pushMagicString);
DateTime dayAfterTomorrow = DateTime.Now.AddDays(2);
Console.WriteLine("Expiry date is: " + dayAfterTomorrow.ToString());
push.QueueNotification(NotificationFactory.Apple()
.ForDeviceToken(test).WithExpiry(dayAfterTomorrow).WithCustomItem("mdm", pushMagicString));
//push.Events.RaiseNotificationSent(NotificationFactory.Apple()
// .ForDeviceToken(hex).WithCustomItem("mdm", pushMagicString));
//Fluent construction of an Android GCM Notification
//push.QueueNotification(NotificationFactory.AndroidGcm()
// .ForDeviceRegistrationId("APA91bG7J-cZjkURrqi58cEd5ain6hzi4i06T0zg9eM2kQAprV-fslFiq60hnBUVlnJPlPV-4K7X39aHIe55of8fJugEuYMyAZSUbmDyima5ZTC7hn4euQ0Yflj2wMeTxnyMOZPuwTLuYNiJ6EREeI9qJuJZH9Zu9g")
// .WithCollapseKey("NONE")
// .WithJson("{\"alert\":\"Alert Text!\",\"badge\":\"7\"}"));
Console.WriteLine("Waiting for Queue to Finish...");
//Stop and wait for the queues to drains
push.StopAllServices(true);
Console.WriteLine("Queue Finished, press return to exit...");
Console.ReadLine();
}
static void Events_OnDeviceSubscriptionIdChanged(Common.PlatformType platform, string oldDeviceInfo, string newDeviceInfo)
{
//Currently this event will only ever happen for Android GCM
Console.WriteLine("Device Registration Changed: Old-> " + oldDeviceInfo + " New-> " + newDeviceInfo);
}
static void Events_OnNotificationSent(Common.Notification notification)
{
Console.WriteLine("Sent: " + notification.Platform.ToString() + " -> " + notification.ToString());
}
static void Events_OnNotificationSendFailure(Common.Notification notification, Exception notificationFailureException)
{
Console.WriteLine("Failure: " + notification.Platform.ToString() + " -> " + notificationFailureException.Message + " -> " + notification.ToString());
}
static void Events_OnChannelException(Exception exception)
{
Console.WriteLine("Channel Exception: " + exception.ToString());
}
static void Events_OnDeviceSubscriptionExpired(Common.PlatformType platform, string deviceInfo)
{
Console.WriteLine("Device Subscription Expired: " + platform.ToString() + " -> " + deviceInfo);
}
}
}
我们使用以下网站将收到的 deviceToken 编码:http://home.paulschou.net/tools/xlate/ 从 base64 到 HEX。
我们还在 iOS 设备上使用 APS/PC 日志记录配置文件,以通过 IPCU 提供的调试控制台获得更多输出。