Search code examples
iosios7apple-push-notifications

C2Call Push Notification


Could you help me check if I miss anything during the configuration, because I couldn't receive notification once the app was killed. If the app was just minimising, a notification will be shown for call, but for instant messaging, the phone only vibrate with a pop sound but showed no notification. Using C2Call How to call below method in AppDelegate sub-class.

[super application:didRegisterForRemoteNotificationsWithDeviceToken]; 



- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
    //[self registerDeviceToken:devToken];
    // Get Bundle Info for Remote Registration (handy if you have more than one app)
    NSString *appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];
    NSString *appVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];

    // Check what Notifications the user has turned on.  We registered for all three, but they may have manually disabled some or all of them.
    //

    NSUInteger rntypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];


    // Set the defaults to disabled unless we find otherwise...

    NSString *pushBadge = @"disabled";
    NSString *pushAlert = @"disabled";
    NSString *pushSound = @"disabled";

    if(rntypes == UIRemoteNotificationTypeBadge){
        pushBadge = @"enabled";
    }
    else if(rntypes == UIRemoteNotificationTypeAlert){
        pushAlert = @"enabled";
    }
    else if(rntypes == UIRemoteNotificationTypeSound){
        pushSound = @"enabled";
    }
    else if(rntypes == ( UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert)){         pushBadge = @"enabled";
        pushAlert = @"enabled";
    }
    else if(rntypes == ( UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)){         pushBadge = @"enabled";
        pushSound = @"enabled";
    }
    else if(rntypes == ( UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)){         pushAlert = @"enabled";
        pushSound = @"enabled";
    }
    else if(rntypes == ( UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)){
        pushBadge = @"enabled";
        pushAlert = @"enabled";
        pushSound = @"enabled";
    }

    // Get the users Device Model, Display Name, Unique ID, Token & Version Number
    UIDevice *dev = [UIDevice currentDevice];
    // NSString *deviceUuid=dev.uniqueIdentifier;
    NSString *deviceUuid = [[dev identifierForVendor] UUIDString];
    NSString *deviceName = dev.name;
    NSString *deviceModel = dev.model;
    NSString *deviceSystemVersion = dev.systemVersion;

    //Prepare the Device Token for Registration (remove spaces and < >)
    NSString *deviceToken = [[[[devToken description] stringByReplacingOccurrencesOfString:@"<"withString:@""]                               stringByReplacingOccurrencesOfString:@">" withString:@""] stringByReplacingOccurrencesOfString: @" " withString: @""];
    NSString *urlString = [@"/pushservice/apns/user/register"stringByAppendingString:@"r=user/register"];
     NSLog(@"devicetoken length: %i", [deviceToken length]);
    urlString = [urlString stringByAppendingString:@"&appname="];
    urlString = [urlString stringByAppendingString:appName];
    urlString = [urlString stringByAppendingString:@"&appversion="];
    urlString = [urlString stringByAppendingString:appVersion];
    urlString = [urlString stringByAppendingString:@"&deviceuid="];
    urlString = [urlString stringByAppendingString:deviceUuid];
    urlString = [urlString stringByAppendingString:@"&devicetoken="];
    urlString = [urlString stringByAppendingString:deviceToken];
    urlString = [urlString stringByAppendingString:@"&devicename="];
    urlString = [urlString stringByAppendingString:deviceName];
    urlString = [urlString stringByAppendingString:@"&devicemodel="];
    urlString = [urlString stringByAppendingString:deviceModel];
    urlString = [urlString stringByAppendingString:@"&deviceversion="];
    urlString = [urlString stringByAppendingString:deviceSystemVersion];
    urlString = [urlString stringByAppendingString:@"&pushbadge="];
    urlString = [urlString stringByAppendingString:pushBadge];
    urlString = [urlString stringByAppendingString:@"&pushalert="];
    urlString = [urlString stringByAppendingString:pushAlert];
    urlString = [urlString stringByAppendingString:@"&pushsound="];
    urlString = [urlString stringByAppendingString:pushSound];

    NSUserDefaults *def=[NSUserDefaults standardUserDefaults];
    [def setObject:deviceToken forKey:@"token"];
    [def synchronize];
   //[super application:didRegisterForRemoteNotificationsWithDeviceToken];

}

Solution

  • - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
    
        [super application:didRegisterForRemoteNotificationsWithDeviceToken];
    
       //[self registerDeviceToken:devToken];
    
      // Get Bundle Info for Remote Registration (handy if you have more than one app)
    
      NSString *appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];
    
      NSString *appVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
    
      // Check what Notifications the user has turned on.  We registered for all three, but they may have manually disabled some or all of them.
    //
    
      NSUInteger rntypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
    
    
      // Set the defaults to disabled unless we find otherwise...
    
      NSString *pushBadge = @"disabled";
    NSString *pushAlert = @"disabled";
    NSString *pushSound = @"disabled";
    
    if(rntypes == UIRemoteNotificationTypeBadge){
        pushBadge = @"enabled";
    }
    else if(rntypes == UIRemoteNotificationTypeAlert){
        pushAlert = @"enabled";
    }
    else if(rntypes == UIRemoteNotificationTypeSound){
        pushSound = @"enabled";
    }
    else if(rntypes == ( UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert)){         pushBadge = @"enabled";
        pushAlert = @"enabled";
    }
    else if(rntypes == ( UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)){         pushBadge = @"enabled";
        pushSound = @"enabled";
    }
    else if(rntypes == ( UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)){         pushAlert = @"enabled";
        pushSound = @"enabled";
    }
    else if(rntypes == ( UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)){
        pushBadge = @"enabled";
        pushAlert = @"enabled";
        pushSound = @"enabled";
    }
    
    // Get the users Device Model, Display Name, Unique ID, Token & Version Number
    UIDevice *dev = [UIDevice currentDevice];
    // NSString *deviceUuid=dev.uniqueIdentifier;
    
    NSString *deviceUuid = [[dev identifierForVendor] UUIDString];
    
    NSString *deviceName = dev.name;
    
    NSString *deviceModel = dev.model;
    
    NSString *deviceSystemVersion = dev.systemVersion;
    
    //Prepare the Device Token for Registration (remove spaces and < >)
    
    NSString *deviceToken = [[[[devToken description] stringByReplacingOccurrencesOfString:@"<"withString:@""]                               stringByReplacingOccurrencesOfString:@">" withString:@""] stringByReplacingOccurrencesOfString: @" " withString: @""];
    
    NSString *urlString = [@"/pushservice/apns/user/register"stringByAppendingString:@"r=user/register"];
    
     NSLog(@"devicetoken length: %i", [deviceToken length]);
    
    urlString = [urlString stringByAppendingString:@"&appname="];
    
    urlString = [urlString stringByAppendingString:appName];
    
    urlString = [urlString stringByAppendingString:@"&appversion="];
    
    urlString = [urlString stringByAppendingString:appVersion];
    
    urlString = [urlString stringByAppendingString:@"&deviceuid="];
    
    urlString = [urlString stringByAppendingString:deviceUuid];
    
    urlString = [urlString stringByAppendingString:@"&devicetoken="];
    
    urlString = [urlString stringByAppendingString:deviceToken];
    
    urlString = [urlString stringByAppendingString:@"&devicename="];
    
    urlString = [urlString stringByAppendingString:deviceName];
    
    urlString = [urlString stringByAppendingString:@"&devicemodel="];
    
    urlString = [urlString stringByAppendingString:deviceModel];
    
    urlString = [urlString stringByAppendingString:@"&deviceversion="];
    
    urlString = [urlString stringByAppendingString:deviceSystemVersion];
    
    urlString = [urlString stringByAppendingString:@"&pushbadge="];
    
    urlString = [urlString stringByAppendingString:pushBadge];
    
    urlString = [urlString stringByAppendingString:@"&pushalert="];
    
    urlString = [urlString stringByAppendingString:pushAlert];
    
    urlString = [urlString stringByAppendingString:@"&pushsound="];
    
    urlString = [urlString stringByAppendingString:pushSound];
    
    NSUserDefaults *def=[NSUserDefaults standardUserDefaults];
    
    [def setObject:deviceToken forKey:@"token"];
    
    [def synchronize];
    }