DipakSonara
DipakSonara

Reputation: 2596

Doesn't get Push Notification with APNS

I have followed this tutorial http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1

As notification has been sent successfully from the server as described in tutorial. But i am not getting it in my device.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
     (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

    if(![[NSUserDefaults standardUserDefaults] valueForKey:@"UUID"])
    {
        if (SYSTEM_VERSION_LESS_THAN(@"6.0"))
        {
            deviceID = [self GetUUID];
        }
        else
        {
            NSUUID* udid= [UIDevice currentDevice].identifierForVendor;
            deviceID = [udid UUIDString];
        }
        [[NSUserDefaults standardUserDefaults] setValue:deviceID forKey:@"UUID"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
    else
    {
        deviceID = [[NSUserDefaults standardUserDefaults] valueForKey:@"UUID"];
    }

    return YES; }

- (NSString *)GetUUID {
        CFUUIDRef theUUID = CFUUIDCreate(NULL);
        CFStringRef string = CFUUIDCreateString(NULL, theUUID);
        CFRelease(theUUID);
        return (__bridge NSString *)string; }

Upvotes: 0

Views: 771

Answers (3)

Ah Ryun Moon
Ah Ryun Moon

Reputation: 370

What's the size of your payload? The maximum length is 256bytes. If your payload is over that limit, it may say the push has been sent successfully yet Apple rejects it silently.

https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html

Upvotes: 0

David Wong
David Wong

Reputation: 10294

Have you implemented application:didReceiveRemoteNotification: in your application delegate? When you're in app notifications get received there.

Or is it no notification gets sent to you?

Upvotes: 1

Nikos M.
Nikos M.

Reputation: 13783

For push notifications you have to register with the push notification token. iOS returns the push notification token with spaces, you have to remove them:

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken 
{

NSString *token = [[devToken description] stringByTrimmingCharactersInSet:      [NSCharacterSet characterSetWithCharactersInString:@"<>"]];
token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
NSLog(@"token: %@", token);
} 

Upvotes: 1

Related Questions