//Create our push services broker var push = new PushBroker(); //Registering the Apple Service and sending an iOS Notification var appleCert = File.ReadAllBytes("ApnsSandboxCert.p12")); //isProduction - development ad-hoc/release push.RegisterAppleService(new ApplePushChannelSettings(isProduction, appleCert, "pwd")); push.QueueNotification(new AppleNotification() .ForDeviceToken("DEVICE TOKEN HERE") .WithAlert("Hello World!") .WithBadge(7) .WithSound("sound.caf")); //Registering the GCM Service and sending an Android Notification push.RegisterGcmService(new GcmPushChannelSettings("theauthorizationtokenhere")); //Fluent construction of an Android GCM Notification //IMPORTANT: For Android you MUST use your own RegistrationId here that gets generated within your Android app itself! push.QueueNotification(new GcmNotification().ForDeviceRegistrationId("DEVICE REGISTRATION ID HERE") .WithJson("{\"alert\":\"Hello World!\",\"badge\":7,\"sound\":\"sound.caf\"}"));
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { // deviceToken, }
+(NSString*)getUserDeviceToken{ return [[NSUserDefaults standardUserDefaults] stringForKey:_deviceTokenKey]; } +(void)setUserDeviceToken:(NSData*)tokenData{ NSCharacterSet *charactersToRemove = [NSCharacterSet characterSetWithCharactersInString:@"<> "]; NSString *result = [[[NSString stringWithFormat:@"%@",tokenData] componentsSeparatedByCharactersInSet:charactersToRemove] componentsJoinedByString: @""]; [[NSUserDefaults standardUserDefaults] setValue:result forKey:_deviceTokenKey]; }
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)]; return YES; }
Source: https://habr.com/ru/post/178775/
All Articles