iOS デバイス向けの MDM ソリューションに取り組んでいます。
Web サイトを介して MDM ペイロードを使用してプロファイルをインストールすることは既に可能であり、PushMagic、deviceToken およびその他の値を含む iOS デバイスから送信された PUT 要求も既に受信しています。
次の説明を使用して 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
この通知を送信するプログラムはエラーをスローせず、正常に終了します。しかし、デバイスでプッシュ通知を受信したり、フィードバック サービスから何も受信したりしていません。
また、sandbox-server と production-server も使用しようとしたことにも言及する必要があります。
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 は、この Web サイト ( http://home.paulschou.net/tools/xlate/ ) を使用 して base64 から HEX にエンコードしました。
また、iOS デバイスで APS/PC Logging プロファイルを使用して、IPCU が提供するデバッグ コンソールからより多くの出力を取得しています。