7

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!

benomatis
  • 5,536
  • 7
  • 36
  • 59
fathik
  • 346
  • 1
  • 2
  • 10

4 Answers4

2

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 :)

DivineDesert
  • 6,924
  • 1
  • 29
  • 61
  • hi I got the device token but it failed to post the values to webservice.In console it shows -JSONValue failed. Error trace is: ( "Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Unrecognised leading character\" UserInfo=0x15e880 {NSLocalizedDescription=Unrecognised leading character} what's the problem? – fathik Oct 12 '12 at 21:04
  • OMG you saved my life, best tutorial EVER! Banging my head for a few hours and in 5 minutes after reading that I just test successfully my first push notification. Thanks man! – Cesar Bielich Dec 12 '18 at 22:09
1

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

Community
  • 1
  • 1
Jai Govindani
  • 3,181
  • 21
  • 26
0
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken 
{    
   NSLog(@"didRegisterForRemoteNotificationsWithDeviceToken: %@", deviceToken); 
   NSString *dt = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]]; 
   dt = [dt stringByReplacingOccurrencesOfString:@" " withString:@""]; 
   self.DeviceToken=dt; 

}
kleopatra
  • 51,061
  • 28
  • 99
  • 211
Bhushan_pawar
  • 157
  • 1
  • 5
0

To get device token, Run application in 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);
}
Vineesh TP
  • 7,755
  • 12
  • 66
  • 130
  • I'm getting this issue.. registerForRemoteNotificationTypes: is not supported in iOS 8.0 and later. – CAN Nov 28 '14 at 09:26