I made an application on urbanairship. Application mode is production. Then i went to provisioning portal at developer.apple.com. In App id section, i went to my app id and downlaoded the production push push Ssl certificate. Export it and made an .p12 file and uploaded it on urbanairship application. Then in xcode, i opened my app and in AppDelegate.m after imports i wrote my urban airship application id and application master secret like this:
Then in AppDelegate.m i have this code for registering device for push notificatons:
If i do the same thing with developement mode and upload the developement push ssl certificate then everything works fine but its not working with production mode. Can anybody tell me why us this happening? I really need help with this. I am stucked here since last one month. Don't know what to do. Thanks in advance
Code:
#define kApplicationKey @"Applicaton id"
#define kApplicationSecret @"Application Master Secret"
Code:
- (BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
// registering device for push notifications
NSLog(@"Registering for push notifications...");
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound)];
return YES;
}
//device registered for remote notifications
- (void)application:(UIApplication*)applicationdidRegisterForRemoteNotificationsWithDeviceToken:(NSData *)_deviceToken {
// Get a hex string from the device token with no spaces or < >
self.deviceToken = [[[[_deviceToken description]stringByReplacingOccurrencesOfString: @"<" withString: @""]
stringByReplacingOccurrencesOfString: @">" withString: @""]
stringByReplacingOccurrencesOfString: @" " withString: @""];
NSLog(@"Device Token: %@", self.deviceToken);
if ([application enabledRemoteNotificationTypes] == UIRemoteNotificationTypeNone) {
NSLog(@"Notifications are disabled for this application. Not registering with Urban Airship");
return;
}
//Update View with the current token
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
self.deviceAlias = [userDefaults stringForKey: @"_UADeviceAliasKey"];
// Display the network activity indicator
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
NSString *UAServer = @"https://go.urbanairship.com";
NSString *urlString = [NSString stringWithFormat:@"%@%@%@/", UAServer, @"/api/device_tokens/", self.deviceToken];
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
[request setHTTPMethod:@"PUT"];
// Send along our device alias as the JSON encoded request body
if(self.deviceAlias != nil && [self.deviceAlias length] > 0) {
[request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:[[NSString stringWithFormat: @"{\"alias\": \"%@\"}", self.deviceAlias]
dataUsingEncoding:NSUTF8StringEncoding]];
}
// Authenticate to the server
[request addValue:[NSString stringWithFormat:@"Basic %@",
[AppDelegate base64forData:[[NSString stringWithFormat:@"%@:%@",
kApplicationKey,
kApplicationSecret] dataUsingEncoding: NSUTF8StringEncoding]]] forHTTPHeaderField:@"Authorization"];
[[NSURLConnection connectionWithRequest:request delegate:self] start];
}
If i do the same thing with developement mode and upload the developement push ssl certificate then everything works fine but its not working with production mode. Can anybody tell me why us this happening? I really need help with this. I am stucked here since last one month. Don't know what to do. Thanks in advance
Last edited: