public string createPlatformApplicationAndAttachToTopic(string deviceToken, string username) { if (deviceToken == null || username == null) { throw new ArgumentException("Passing null device token or username"); } var topicRequest = new CreateTopicRequest { Name = username + "_myTopic" }; var topicResponse = snsClient.CreateTopic(topicRequest); var createPlatformApplicationRequest = new CreatePlatformApplicationRequest { // Platform Credential is the SERVER API KEY FOR GCM Attributes = new Dictionary <string, string>() { { "PlatformCredential", API_KEY }, { "EventEndpointCreated", topicResponse.TopicArn } }, Name = username + "_platform", Platform = "GCM" }; var createPlatformResponse = snsClient.CreatePlatformApplication(createPlatformApplicationRequest); string platformApplicationArn = createPlatformResponse.PlatformApplicationArn; var request1 = new CreatePlatformEndpointRequest { CustomUserData = "", PlatformApplicationArn = platformApplicationArn, Token = deviceToken }; // Getting the endpoint result // It contains Endpoint ARN that needs to be subscripted to a topic var createPlatformEndpointResult = snsClient.CreatePlatformEndpoint(request1); try { snsClient.Subscribe(new SubscribeRequest { Protocol = "application", TopicArn = topicResponse.TopicArn, Endpoint = createPlatformEndpointResult.EndpointArn }); } catch (Exception e) { Console.WriteLine(e.Message.ToString()); return(null); } return(topicResponse.TopicArn); }
public static void SNSMobilePushAPIsCreatePlatformApplication() { #region SNSMobilePushAPIsCreatePlatformApplication var snsClient = new AmazonSimpleNotificationServiceClient(); var request = new CreatePlatformApplicationRequest { Attributes = new Dictionary <string, string>() { { "PlatformCredential", "AIzaSyDM1GHqKEdVg1pVFTXPReFT7UdGEXAMPLE" } }, Name = "TimeCardProcessingApplication", Platform = "GCM" }; snsClient.CreatePlatformApplication(request); #endregion }
public string[] createPlatformApplication(string deviceToken, string username) { if (deviceToken == null || username == null) { throw new ArgumentException("Passing null device token or username"); } var createPlatformApplicationRequest = new CreatePlatformApplicationRequest { // Platform Credential is the SERVER API KEY FOR GCM Attributes = new Dictionary <string, string>() { { "PlatformCredential", API_KEY } }, Name = username + "_platform", Platform = "GCM" }; var createPlatformResponse = snsClient.CreatePlatformApplication(createPlatformApplicationRequest); string platformApplicationArn = createPlatformResponse.PlatformApplicationArn; var request1 = new CreatePlatformEndpointRequest { CustomUserData = "", PlatformApplicationArn = platformApplicationArn, Token = deviceToken }; // Getting the endpoint result // It contains Endpoint ARN that needs to be subscripted to a topic var createPlatformEndpointResult = snsClient.CreatePlatformEndpoint(request1); string[] arr = new string[2] { "", "" }; arr[1] = createPlatformEndpointResult.EndpointArn; arr[0] = platformApplicationArn; return(arr); }