Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get device token?

I am posting values of username,password and devicetoken to .net webservice. But It didn't get any device token value. I am using below code.

- (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 console it shows

Failed to get token, error: Error Domain=NSCocoaErrorDomain Code=3000 "no valid 'aps-environment' entitlement string found for application" UserInfo=0x1a0810 {NSLocalizedDescription=no valid 'aps-environment' entitlement string found for application

Any idea? Thanks in advance!

like image 742
fathik Avatar asked Oct 11 '12 19:10

fathik


2 Answers

Have you enabled push notification in your provisional file ?

Go through the tutorial to check if you have done right

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

like image 196
DivineDesert Avatar answered Sep 28 '22 07:09

DivineDesert


I'm assuming you're running/debugging on a device since you'd get a different error trying to register for a push token from the simulator. Just wanted to get that out of the way.

That being said, what usually causes the error you're seeing is that Push Notifications aren't enabled in the Provisioning Profile that you've selected. Now, you might have gone in to the iOS Provisioning Portal and enabled Push for your App ID (also note if you've enabled Push for your Development or Distribution profile). However, after doing that, you have to go in and 'dirty' your Provisioning Profile for the Provisioning Portal to generate a new Provisioning Profile that has the push entitlements in it.

By 'dirtying' it I mean going in and changing some setting of the profile to force a re-creation. You'll know if you 'dirtied' it enough if when you go back to the list of Provisioning Profiles, the status changes temporarily to 'Pending' for a few seconds before becoming 'Active' again and allowing you to download it.

Oh, and I just found this which also answers the question (someone help out if I linked it wrong please): Bundle Identifier and push certificate... aps-environment entitlement error

like image 33
Jai Govindani Avatar answered Sep 28 '22 05:09

Jai Govindani