TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Mukesh Kumar Tiwari
NA
980
251.4k
Send Notification To iPhone Using WCF.
Nov 30 2017 10:07 PM
Hello,
I am tryinh to send the notifictions to iPhone. And i ahev made a fucntion for that , there is not any bug in code, fucntion excuted successfully, but notifiction could not send th the iphone device.
Can any one help out from this, please....
Below is my code..
tiwari-mike
public void SendMessageiOS(string deviceID, string message)
{
int port = 2195;
String hostname = "gateway.push.apple.com";
//C:\Windows\System32\inetsrv
//load certificate
string certificatePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Loyalty_Prod_Certi.p12");
string certificatePassword = "1234";
// string certificatePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "_DistriCertificates.p12");
// X509Certificate2 clientCertificate = new X509Certificate2(System.IO.File.ReadAllBytes(certificatePath), "1234");
X509Certificate2 clientCertificate = new X509Certificate2(certificatePath);
X509Certificate2Collection certificatesCollection = new X509Certificate2Collection(clientCertificate);
TcpClient client = new TcpClient(hostname, port);
SslStream sslStream = new SslStream(
client.GetStream(),
false,
new RemoteCertificateValidationCallback(ValidateServerCertificate),
null
);
try
{
sslStream.AuthenticateAsClient(hostname, certificatesCollection, SslProtocols.Tls, true);
}
catch (Exception ex)
{
client.Close();
return;
}
MemoryStream memoryStream = new MemoryStream();
BinaryWriter writer = new BinaryWriter(memoryStream);
writer.Write((byte)0); //The command
writer.Write((byte)0); //The first byte of the deviceId length (big-endian first byte)
writer.Write((byte)32); //The deviceId length (big-endian second byte)
//byte[] AppID = Encoding.UTF8.GetBytes(deviceID.ToUpper());
writer.Write(StringToByteArrayFastest(deviceID.ToUpper()));
//writer.Write(AppID);
String payload = "{\"aps\":{\"alert\":\"Message\",\"badge\":0,\"sound\":\"default\"}}";
payload = payload.Replace("
Message
", message);
writer.Write((byte)0);
writer.Write((byte)payload.Length);
byte[] b1 = System.Text.Encoding.UTF8.GetBytes(payload);
writer.Write(b1);
writer.Flush();
byte[] array = memoryStream.ToArray();
sslStream.Write(array);
sslStream.Flush();
client.Close();
}
Reply
Answers (
1
)
Solution and technology for between clients and servers
How to Upload and Download CAD files in web api?