i edit and modify the provisioning profile alot of times. and i checked it in text editor too. everything is ok with provisioning profile. but still push notifications are not working. and i m getting this error. everyone is saying that its bcz of bad provisioning profile but my provisioning profile values are the same as Apple said in their documentation. i m getting this error:
Error in registration. Error: Error Domain=NSCocoaErrorDomain
Code=3000 "no valid 'aps-environment' entitlement string found for
application" UserInfo=0x127d80 {NSLocalizedDescription=no valid
'aps-environment' entitlement string found for application}
code lookes like this in my AppDelegate.m:
- (BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions {
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
-(void)application:(UIApplication )application didRegisterForRemoteNotificationsWithDeviceToken:(NSData )deviceToken {
NSString *deviceTokenStr = [[[[deviceToken description] stringByReplacingOccurrencesOfString: #"<" withString: #""] stringByReplacingOccurrencesOfString: #">" withString: #""] stringByReplacingOccurrencesOfString: #" " withString: #""];
NSLog(#"DeviceTokenStr: %#",deviceTokenStr);
}
Thanx for help in advance
I believe the "no valid 'aps-environment' entitlement string found for application" error appears when you don't sign your app with the correct provisioning profile. You'll have to generate a profile for your app as described in Mahesh's link). Also note that you can't use a team provisioning profile to sign an app that requires push notifications.
Related
I want to send the device token to server in my application. I am using following method to retrieve the device token.
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSLog(#"deviceToken: %#", deviceToken);
}
but not worked in ios6. How can do this?
Have you written this line
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
inside this function,
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
It should work in iOS 6 if you have done this.
If you are using Urbanariship you need to clean up the deviceToken before sending it back via a NSURLConnection PUT to the urbanairship servers.
NSString *deviceToken = [[_deviceToken description] stringByReplacingOccurrencesOfString: #"<" withString: #""];
deviceToken = [deviceToken stringByReplacingOccurrencesOfString: #">" withString: #""] ;
deviceToken = [deviceToken stringByReplacingOccurrencesOfString: #" " withString: #""];
Other wise you can send using NSURequest/ NSURLConnection
Hope this will help you out. or just let us know if you want code for Request and Connection as well.
I have tried so many tutorials for sending Push notification service for my app.When i'm testing it on device it works. but if i'm testing it on live after my app launches on App store and i installed it on my device by downloading from store and i run the php file for sending the Push Notification i'm not getting it.Here is the code which i used for Push notification and the tutorial i learnt from .
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
[[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);
}
Is there any tutorial which can teach me to have it on live.I changed the environment of my php file from sandbox to live.Guidance please.
I solved this on my own.
The reason for not working it on Live is because of the
(void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
in this method the device token not id properly registered with my php server database. The following code will help to register the device token in php server
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
NSLog(#"My token is: %#", deviceToken);
NSString* newToken = [deviceToken description];
newToken = [newToken stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:#"<>"]];
newToken = [newToken stringByReplacingOccurrencesOfString:#" " withString:#""];
NSLog(#"%#",newToken);
NSString *urlString = [NSString stringWithFormat:#"http://sample.com/registerDevice.php?appId=xxx&deviceToken=%#",newToken];
NSURL *url = [[NSURL alloc] initWithString:urlString];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
NSData *urlData;
NSURLResponse *response;
urlData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:nil];
NSLog(#"data send");
}
First, I don't think installing an application with a development push notification certificate (or ad-hoc certificate), getting the deviceToken, installing the app store application and sending the push notification using the previous device token will work.
This link confirms it : iPhone APNS Device Tokens in sandbox vs. production
This probably explains why you cannot send a push notification to your application.
Also, you need to send the device token to your server, cause it's the only way for your server to know all the device tokens.
I advise you to review the apple documentation.
I need to obtain the device token on my iPhone to test the push notify.
On my iPhone I had already agreed to notify push permissions. I try to remove and reinstall the app but nothing. I try to put a breackpoint in the didRegisterForRemoteNotificationsWithDeviceToken method but nothing.
Any suggestion?
This is my code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
/**** PUSH NOTIFY ****/
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSMutableString *str = [[NSMutableString alloc] initWithFormat:#"http://www.mysite.com/storeToken.php?task=register&token=%#", [self stringWithDeviceToken:deviceToken]];
//NSLog(#"%#",str);
NSUserDefaults *pref = [NSUserDefaults standardUserDefaults];
[pref setObject:[self stringWithDeviceToken:deviceToken] forKey:#"token"];
[pref synchronize];
NSURL *url = [NSURL URLWithString:str];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request startSynchronous];
[str release];
}
- (NSString*)stringWithDeviceToken:(NSData*)deviceToken {
const char* data = [deviceToken bytes];
NSMutableString* token = [NSMutableString string];
for (int i = 0; i < [deviceToken length]; i++) {
[token appendFormat:#"%02.2hhX", data[i]];
}
return [[token copy] autorelease];
}
This is the error that it print:
Error: Error Domain=NSCocoaErrorDomain Code=3000 "nessuna stringa di autorizzazione 'aps-environment' valida trovata per l'applicazione" UserInfo=0x296e80 {NSLocalizedDescription=nessuna stringa di autorizzazione 'aps-environment' valida trovata per l'applicazione}
It is good to have another delegate method for error handling:
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(#"Fail to register for remote notifications: %#", [error localizedDescription]);
}
After question update it's more clear that problem is in wrong provisioning profile (generic or without 'aps-evironment'). So:
Remove all expired profiles and all profiles for that app from both XCode and device
Check push notifications are enabled for your app (in provisioning portal)
Download provisioning profile from portal, install it to XCode
Check that selected profile (in build settings / codesigning identity) matches the app, and is not the generic/wildcard one (sometimes autoselection goes wrong)
As usual (XCode caching "magic"), it's better to restart XCode and remove the application from device before build
Build & Pray
I have a standard implementation of the Single Sign On for iOS with the AppDelegate listening for the handleOpenURL. Prior to today, this implementation was working fine. I have made no changes to the implementation today, yet the redirect from Facebook in Safari ( on the Simulator ) and the redirect from Facebook app ( on the actual device ) no longer return any data to my app.
I am forwarded to login without issue and login successfully to see that I have already authorized the current app and can now click "Okay", which I do. When the app returns to focus ( after Facebook redirects back to it ), there is no data returned with the redirect.
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
NSLog(#"url recieved: %#", url);
NSLog(#"query string: %#", [url query]);
NSLog(#"host: %#", [url host]);
NSLog(#"url path: %#", [url path]);
// from facebook login
if ( [[url scheme] isEqualToString:FACEBOOK_URL_SCHEME] ) {
return [SESSION.facebook handleOpenURL:url];
}
return YES;
}
The values for all of the logs are empty - the app logs nothing. The request to authorize is below:
NSArray *permissions = [[NSArray alloc] initWithObjects:
#"publish_actions",
#"email",
#"user_checkins",
#"user_likes",
#"user_photos",
#"offline_access",
#"publish_stream",
#"read_friendlists",
nil];
[SESSION.facebook authorize:permissions];
Again, this very code worked perfectly yesterday and for the last 3 weeks. Today it simply stopped working. Any help is appreciated. Please let me know if more code is needed to evaluate the issue.
Thanks in advance!
Jane
Now - for no explainable reason it is working again. I did check Facebook SDK Status prior to posting here and everything was green. I guess I'll chalk this one up to a blip in the internets.
I "think" my app is not registering for push notifications.
It should be as simple as adding the code to didFinishLaunchingWithOptions and then the when tested the app alert for push notifications should (but does not in my case) pop up.
my code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge |UIRemoteNotificationTypeSound)];
return YES;
}
This is an iPad app. It is running without push on my real device so I assume the provisioning is correct.
Any ideas? I do not get the push Don't allow/ok pop up.
Do u have this code in your delegate?
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSString *str = [NSString
stringWithFormat:#"Device Token=%#",deviceToken];
NSLog(str);
}
You should get the device token generated and put it in your server where you want to push your notification..
If let say you have everything right on the iphone part, the problem may lies on your server code where you push your notification..
Take a look at this tutorial about push notification :
http://mobiforge.com/developing/story/programming-apple-push-notification-services
You need to implement the delegate methods and set up the certificates on your server. Here is some code for the objc side:
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
NSString *token = [[devToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:#"<>"]];
[[NSUserDefaults standardUserDefaults] setObject:token forKey:#"token"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
[[NSUserDefaults standardUserDefaults] setObject:[NSString stringWithString:#""] forKey:#"token"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:[[[NSBundle mainBundle] infoDictionary] objectForKey:#"CFBundleDisplayName"]
message:[[userInfo objectForKey:#"aps"] objectForKey:#"alert"]
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil] autorelease];
[alert show];
}
A good tutorial about setting up the server and Dev Center certs - How to renew your Apple Push Notification Push SSL Certificate
How to build an Apple Push Notification provider server (tutorial)
Yes I have the other part of the code also. I was under the impression that the pop up would happen weather the server stuff was done yet or not?
I got it working. I had to get a new provisioning file. Delete the old one. The go into the app folder. View contents of the project file. Open with text editor the file with the provisioning key in it and swap the key (two spots) out with the new key code.
Now it works. Thanks for the help.