Push notification not working - objective-c

I am trying to send push notifications to myself.
I have copied the code from Apple. But I am getting the error no valid 'aps-environment' entitlement string found for application.
I made a new project with the same code (without adding entitlements.plist)and it's working fine.
so it's not the problem of my provisioning profile or my code, then what is?
Can someone tell me why it isn't working on my main project?
thanks in advance

This means that the provisioning profile used to build the application does not have push notifications enabled. Push notifications must be enabled for that application ID in the iTunes Developer Portal.
If you’ve already enabled push notifications and still receive this error, it might be because you enabled push notifications after the provisioning profile was created. In this case, the profile will not have the required push notification settings, and must be regenerated.
To regenerate the provisioning profile, find it in the iTunes Developer Portal, and click Edit->Modify and save it. When you download the new profile, we recommend removing the existing profile from the device and XCode before installing the new one. Many developers continue to report problems unless they do this step.

Related

Error with 'com.apple.developr.aps-environment' when validating mac application on xcode

In an application I made for Mac, when I ran the process for validating the archive, it came up with the error:
The archived application has entitlements that require Mac App Store distribution.
The invalid entitlements were:
com.apple.developer.aps-environment.
I looked at this link: Enabling Push Notifications and the entitlement, I think, is in relation to the push notifications.
I tried adding the
com.apple.developer.aps-environment
to my entitlements file as a boolean set to YES, but the error still came up.
How can I fix this?
It looks like you're maybe trying to sign the app for distribution outside the App Store, and Xcode is telling you it's not going to let you do that because you're using App Store only features.
I'm no expert in signing stuff, but to get my last app to submit I signed it with the "3rd Party Mac Developer Application:..." identity, not my "Developer ID:" identity. The latter is only for when you're distributing apps directly to customers from your own website.
It's not a boolean. It's a string that's either 'development' or 'production'. It's also only for apple store only.

Device Token null when deploying app as ad-hoc (Urban Airship)

I implemented the Urban Airship library into my application and I can successfully send push notifications to a specific device in development mode. After startup I get the device token and save it into a mysql database. However, when I use the app in ad-hoc mode, the device token is always (null).
APP_STORE_OR_AD_HOC_BUILD is set to YES
and the APP Key and APP-Secret for both production and development are correct.
Any ideas how to get the device token in ad-hoc/appstore mode?
Edit:
Identical question has been posted in the Urban Airship Forum.
For me also same thing happened. What we did to solve problem is just recreated new adHoc provisioning profile. Then we got alert asking to install push notification. Its one of the major issue in iOS push notification. We must configure push nofitiation SSL certificate before creating provisioning profile.

Modal alert request for push notifications

debuggers,
I have created an app that embeds push notifications.
For one or other reason the user does not get asked for permission on the first load.
In the past I have used push notification and everything seemed to work, the code for is pretty much "copy-pasted".
I requested a certificate from a certificate authority (keychain)
I enabled push notification and downloaded a new certificate
Uploaded the certificate to apple and received a validated development and distribution certificate.
I downloaded a new development + production provisioning profile.
I signed the app with the provisioning profile.
When I open the provisioning profile in textedit I do see the following key:
aps-environment
I used this profile to sign the app and install it on to the device!
I have tried several methods like setting the time on my phone to days ahead, rebooting, re-installing.
I use urban airship as a push service!
Does anyone have any idea what is going wrong?
Do you have [UAPush setDefaultPushEnabledValue:NO] set by any chance?
By setting this value to NO UrbanAirship delay prompting users to enable push notifications until you are ready to ask. This gives you a chance to explain what they are used for instead of it popping up right when the app starts.
Then later you can enable them by calling
UIRemoteNotificationType notificationTypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

IOS Provisioning Profile and Push Notification on New Device

I can send push notification to an IOS device (IOS 5.1 IPAD 3rd gen) and handle notifications etc.. So it works quite well.
Now I have to use another device(IOS 5.1 IPAD 3rd gen), on organizer by right clicking I add my device to provisioning profile I can install my app to device but I can not send push notifications because I can not get device's token.
I guess it is because when I right click and add device to my provisioning profile It only adds the iOS Team Provisioning Profile rather then myApp Development Profile
On apples developer portal I have:
On My Organizer In Library-->Provisioning Profiles
On my teams
And I handle error code on push Notification:
- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
NSLog(#"Failed to get token, error: %#", error);
}
Error Is: Failed to get token, error: Error Domain=NSCocoaErrorDomain Code=3000 "no valid 'aps-environment' entitlement string found for application" UserInfo=0xxxxxxx {NSLocalizedDescription=no valid 'aps-environment' entitlement string found for application}
In case error is because provisioning profile:
How can add that Paper Developement profile to my device?
or
How can I learn device token and send push notification without creating provisioning profile all over?
Thanks in advance
I had similar issues before so I will list your possible issues,
Firstly do not use a provisioning profile with a wild card it is highly possible that your IOS Team Provisoning Profile includes a wild card. So just go to your device's provisioning profile on organizer and delete that IOS Team Provisoning Profile
Secondly go to your provisoning profiles on developer.apple and click edit as on your second picture in question. When you click edit you will see Modify click on that
and add your device by checking squares like below:
Click save and download new profile, now go to your provisioning profiles on your organizer and delete previous Pape Developement Profile. Double click your downloaded profile or click refresh on your organizer. Now drag and drop proviosinig profile to your device on organizer.
Finally if none of above solves your problem that means probably your bundle identifier and your app id does not much in this case check this answer
Hope you solve this issue....
For me it was just changing the bundle identifier and code signing identity to IOS Developer. The bundle identifier Changing it back and forth and building between changes did the trick (not sure if this step necessary). Not sure what it really was. Hope this helps someone someday, probably not.

Push notifications not asking permission when user loads app

Hi I have just released my app update with push notifications added into it. I was worried that it would not work properly so I did a bunch of testing. First with just a development certificate and then a production certificate using adhoc. Both ended up working and I was pleased when the adhoc worked.
Anyways the update has been live for about 8 hours now and for some reason push isn't working. I checked with my friend and have realized that the user is not being asked whether he wants to accept push notifications from my app. Which means when the token gets sent to my server, its appearing as (null). I have no idea why this is happening. When he goes into device settings --> notifications ---> my app does not appear on any of the lists (receiving push notifications or not receiving).
This is the code in my delegate that should trigger the request:
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
If anyone knows why this is happening, input would be much appreciated. Thanks!
We thought we were having this same issue but found out that the app was actually working correctly. The user is only prompted once even if they uninstall and reinstall the app.
We were testing it by uninstalling the app and then reinstalling. iOS would remember how we had responded previously on that device and would not prompt again leading us to think there was a problem.
We found the best way to test is with the simulator and doing a "Reset Content and Settings".
After configuring your app for push notifications and generating your SSL certificates you must also generate new provisioning profiles.
The developer portal displays this message on the App ID configuration page:
After you have generated your Client SSL certificate, create a new provisioning profile containing the App ID you wish to use for notifications.
If you did not update your App Store provisioning profile after setting up push the OS will not provide you with a push token.
If this is your problem you just need to generate a new App Store distribution profile and submit a recompiled version signed with that profile.