No response for Device token request on the simulator - ios

I am newbie to iphone technology,right now i m working with an application where i need to implement push notification.
I followed the link :
http://mobiforge.com/developing/story/programming-apple-push-notification-services#comment-7850
Also,Used the following code :
NSLog(#"Registering for push notifications...");
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:
(UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound)];
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSString *str = [NSString stringWithFormat:#"Device Token=%#",deviceToken];
NSLog(str);
}
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err
{
NSString *str = [NSString stringWithFormat: #"Error: %#", err];
NSLog(str);
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
for (id key in userInfo)
{
NSLog(#"key: %#, value: %#", key, [userInfo objectForKey:key]);
}
}
Thing is,when i run the program,i should get device token in the debugger window,as per the code,instead i am getting error like :
" Error in registration. Error: Error
Domain=NSCocoaErrorDomain Code=3010
"remote notifications are not
supported in the simulator"
UserInfo=0x6e055a0
{NSLocalizedDescription=remote
notifications are not supported in the
simulator} "
How should i solve this problem?
Kindly help me out.
Thank you.

Because the simulator doesn't support it... In the example it displays the device identifier in the console. The console is displaying the feedback from the device. It isn't the console that is getting the information, but the device sending the information back. So, just because the console displays information on your Mac doesn't mean your Mac is capable of directly getting that information. Sometimes it must be sent by the device. Try running it on a device.

The error message is self explaining, you should try to debug the app on real device not on the simulator, as push notifications are not supported to be received on the simulators.

Related

iOS- Push notification issue

Currently one of my php developer provided me push notification API for iOS devices
The problem is : If i run that api with respective parameter in any Browser(Chrome/Safari/Firefox and etc..) i am getting notification on foreground of iOS device. But not in iOS app(Xcode) itself
In my app i used code like:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Register for Push Notitications, if running on iOS 8
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
}
#pragma mark
#pragma mark -- Push Notification Delegate Methods
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings: (UIUserNotificationSettings *)notificationSettings{
//register to receive notifications
[application registerForRemoteNotifications];
}
-(void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken{
// Prepare the Device Token for Registration (remove spaces and < >)
devToken = [[[[deviceToken description]
stringByReplacingOccurrencesOfString:#"<"withString:#""]
stringByReplacingOccurrencesOfString:#">" withString:#""]
stringByReplacingOccurrencesOfString: #" " withString: #""];
NSLog(#"My token is: %#", devToken);
// My token is: cd2887c4093569b3eed142320f21a81e521e486cf5c40467390901d3a191398b
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setValue:deviceToken forKey:#"deviceToken"];
}
-(void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error{
NSLog(#"Failed to get token, error: %#", error);
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
NSLog(#"%s..userInfo=%#",__FUNCTION__,userInfo);
}
I am getting response:(in didReceiveRemoteNotification)
{
aps = {
alert = "You're login successfully";
sound = default;
};
}
This message is not showing on Status bar(top of the screen). Is there any issue in iOS side (or) PHP side
If the issue is in iOS side--> How can i do this
Here is my Testing Push notification API:
https://shopgt.com/mobile1/iphone/register.php?device_type=2&email=sukhpal#anaad.net&regId=4d1d9067cc1382ecb8b0532831cce7fc8eb6fc388a6139060cd84712407a0ae5
Can you please help me out regarding this issue
You need to customize the view for showing Banner of Push Notification while the app in Foreground. You can use JCNotificationBannerPresenter. Follow the sample code using below link.
https://github.com/jcoleman/JCNotificationBannerPresenter
#import "JCNotificationCenter.h"
#import "JCNotificationBannerPresenterSmokeStyle.h"
- (void) application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)notification {
NSString* title = #"Push Notification";
NSDictionary* aps = [notification objectForKey:#"aps"];
NSString* alert = [aps objectForKey:#"alert"];
[JCNotificationCenter
enqueueNotificationWithTitle:title
message:alert
tapHandler:^{
NSLog(#"Received tap on notification banner!");
}];
}
Hope it Helps you..!
There is no issue, this is default behaviour.
The banner that appears at the top of the screen when you are on the Home screen does not appear when you are inside the app.
You need to get the app to do something with the notification yourself, inside didReceiveRemoteNotification. This could be showing an alert, adding a badge to the tab bar, etc. but banners only show when you are outside of the app.

iOS Push Notifications is not received

Backend - Django
Frontend - Objective C (X-code)
I've followed this Apple Document to configure Push Notifications and successfully completed all steps.
For Backend, I am using django-push-notifications with Django==1.7 and it results into no error when message is sent.
For Frontend, I have added following lines to receive the notification,
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge |
UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSString *token = [[deviceToken description] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:#"<>"]];
token = [token stringByReplacingOccurrencesOfString:#" " withString:#""];
NSLog(#"content---%#", token);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"DeviceToken!!!" message:token delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:nil];
[alert show];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
....
}
But after this, I am not able to receive the notification. Have I completed and configured steps correctly? My X-code version is 6.3 and Apple Device with iOS version on 8.4. Should both be compatible versions to receive the notifications?
Is there any way to log or view the progress at APNs cloud?
Use deviceToken directly like
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken {
NSLog(#"My token is: %#", deviceToken);
}
Also you need to be sure that you're sending Push-notification.
Try to use this tutorial and their application it will help you to be sure that you're sending Push correctly and you need to fix frontend.
Check whether the device token are getting updated to your server.
Check the mode of push operation. Development or Distribution? Provision your application based on that.
Confirm that APNS service is enabled in your application and you are provisioned your app using that mobile provision.(In member center).
Also check whether the .pem is proper or not?
If everything is proper, the try deleting the existing build, restart the phone and install new build and try.

iPhone 6 and 6 Plus Can Not Receive Remote Push Notifications

I have a really strange problem with my app on iPhone 6 and 6 Plus (iOS 8.2). I've followed and read almost everything (I Think!) that I found on the web to figure this out, but still it doesn't work. I've tested the app on iPhone 4 (iOS 7.1), 4s (iOS 7.1), 5s (iOS 8.1) and iPad Mini (iOS 8.2) and they all can receive the push notifications on from the app. My XCode version is 6.2 and the iPhone 6 devices (iOS 8.2) are detected as ineligible devices on it. So I can't even run the app right from XCode.
I'm using php script to push the notifications. When the app first run on iPhone 6, it showed up a pop up alert asking for the push notification permission. On the device's settings, the app is there on the notifications settings. I've tried revoking the apns certificate and creating a new one, re-generating the .pem files, reseting the device contents and settings, uninstall and install the app. None of these ever worked and I am already pulling my hair out. I even asked the Apple technical support for this but their answer is really just blah. I've tried downloading an app from the app store that has push notifications feature. And somewhat the device can receive push notifications from that app. So, is there anything that I am missing here? Can someone help me in this?
As suggested, here's my code for registering the notifications. I called the method "registerForRemoteNotification" from inside "application:didFinishLaunchingWithOptions:" :
- (void)registerForRemoteNotification
{
if ([[UIApplication sharedApplication] respondsToSelector:#selector(registerUserNotificationSettings:)])
{
NSLog(#"system version >= 8.0");
UIUserNotificationType types = UIUserNotificationTypeSound | UIUserNotificationTypeBadge | UIUserNotificationTypeAlert;
UIUserNotificationSettings *notificationSettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
}
else {
NSLog(#"system version < 8.0");
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
}
}
#ifdef __IPHONE_8_0
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
NSLog(#"Registering for remote notification");
[application registerForRemoteNotifications];
}
#endif
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSLog(#"did register remote notification with device token");
NSString *newToken = [deviceToken description];
newToken = [newToken stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:#"<>"]];
newToken = [newToken stringByReplacingOccurrencesOfString:#" " withString:#""];
NSLog(#"Device token: %#",newToken);
DataManager *sharedData = [DataManager sharedInstance];
sharedData.deviceToken = newToken;
[self requestProfileWithDeviceToken:newToken];
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSLog(#"Failed to get device token, error: %#", error);
[self requestProfileWithDeviceToken:#""];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
NSLog(#"Receive push notification: %#",userInfo);
[self processPushNotification:userInfo];
}
Any help would be very much appreciated. Cheers.

push notifications iOS add device

I get a new iPhone and when i tried to test it with a Xcode project with push notifications , it doesn't get token , always failed to get token , i think this because when i was creating the certificate i didn't mark on the device , now i want to add this device to the testing and get token what i should do ??
- (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);
}
For that you should first set Provisioning profile in which you have added your device UDID.
then Add below code to register Pushnotification in device. so when you run your app first time it will ask you for permission .
//Push Noti
[[UIApplication sharedApplication]registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound)];
If you allow then below delegate will be called. and it will give you device token.
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSString *strDeviceToken = [[[[[deviceToken description]stringByReplacingOccurrencesOfString: #"<" withString: #""] stringByReplacingOccurrencesOfString: #">" withString: #""]stringByReplacingOccurrencesOfString:#" " withString: #""]copy];
NSLog(#"%#",strDeviceToken);
}
If you dont allow then below delegate method will be called
- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
NSLog(#"Failed to get token, error: %#", error);
}
Maybe it will help you.

Why my iPod touch 4 cannot register APNS?

I am trying to test my app on iPod touch 4, however I need APNS support.
I found out that neither delegate callbacks for APNS is called.
I've searched through the Technical Note, and it doesn't help (for the same code works for my iPad2, that the device token is returned).
Any idea on this?
I am using iPod touch 4 with iOS 5.1.1
Edit:
Ah, more information provided here.
I have create a provisioning profile before as well as all those certificates. That's why I can work that out with iPad.
Then today, I just added my iPod touch 4 as the development device and downloaded the provisioning profile again. Will this act not registering my iPod touch 4 to be able for handling APNS job????
Edit 2:
As requested:
Actually I just do whatever Apple requested me to do,
that I included
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: NSDictionary *)launchOptions
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge)];
//Other codes...
}
Then, the two delegates callback methods
#pragma mark - For Apple Push Notification Service
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSString *str = [NSString
stringWithFormat:#"%#",deviceToken];
NSString *devToken = [[[[str description]
stringByReplacingOccurrencesOfString:#"<"withString:#""]
stringByReplacingOccurrencesOfString:#">" withString:#""]
stringByReplacingOccurrencesOfString: #" " withString: #""];
NSLog(#"%#", devToken);
NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
if (standardUserDefaults)
{
[standardUserDefaults setObject:devToken forKey:#"device_token"];
[standardUserDefaults synchronize];
}
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSLog(#"application:didFailToRegisterForRemoteNotificationsWithError: %#", error);
}
Actually, I just copy and paste what Apple provided me.
However the case is just as mentioned above, either method is called for iPad2 with iOS 5.0.1, iPhone with iOS 4.3 but not for my iPod Touch 4 with iOS5.1.1.

Resources