How to get a device token?

I send the username, password and devicetoken values ​​to the .net webservice. But he did not receive the device token value. I am using the code below.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0]; [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeAlert ]; } - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { NSLog(@"didRegisterForRemoteNotificationsWithDeviceToken: %@", deviceToken); NSString *dt = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]]; dt = [dt stringByReplacingOccurrencesOfString:@" " withString:@""]; self.DeviceToken=dt; NSLog(@"~~~~devToken(dv)=%@",deviceToken); } - (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error { NSLog(@"Failed to get token, error: %@", error); } 

But in the console it shows

Could not get token, error: Error Domain = NSCocoaErrorDomain Code = 3000 "no valid" aps-environment matching string found for the application "UserInfo = 0x1a0810 {NSLocalizedDescription = no valid" aps-environment "permission string found for the application

Any idea? Thanks in advance!

+6
source share
4 answers

Did you activate the push notification in the preliminary file?

Go through the tutorial to check if you did the right thing.

First try sending a push notification to the device from your mac, as described in the tutorial. You will need a server side pem file that you need to create with iOS Portal :)

+1
source

I assume that you are running / debugging on the device, since you will get another error trying to register for the token token from the simulator. Just wanted to get it out of the way.

This usually causes the error that you see, so that Push Notifications are not included in the selected Provisioning Profile. Now you may have logged into the IOS Provisioning Portal and enabled Push for your application ID (also note if you enabled Push for your development or distribution profile). However, after that you need to log in and “pollute” your Provisioning profile for the Provisioning Portal in order to create a new Provisioning Profile that has rights to it.

By "dirty", this means switching and changing some profile settings to force a re-creation. You will find out if you just need to “pollute” if, having returned to the list of Provisioning Profiles, the status temporarily changes to “Waiting” for a few seconds before becoming “Active” again and allowing it to be downloaded.

Oh, and I just found this, which also answers the question (someone will help if I connected it incorrectly): Package ID and click certificate ... aps-environment

+1
source
 - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { NSLog(@"didRegisterForRemoteNotificationsWithDeviceToken: %@", deviceToken); NSString *dt = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]]; dt = [dt stringByReplacingOccurrencesOfString:@" " withString:@""]; self.DeviceToken=dt; } 
0
source

To get the device token, run the application on the device .

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Let the device know we want to receive push notifications [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)]; return YES; } - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken { NSLog(@"My token is: %@", deviceToken); } - (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error { NSLog(@"Failed to get token, error: %@", error); } 
0
source

Source: https://habr.com/ru/post/927495/


All Articles