Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7410147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:11:17+00:00 2026-05-29T06:11:17+00:00

I am implementing a push notification in my application. Server: php Client: iphone Sever

  • 0

I am implementing a push notification in my application.

Server: php
Client: iphone

Sever side Coding:

function pushToIphone($deviceToken, $badge){
    ini_set('display_errors','on');
    error_reporting(E_ALL);

    //$apnsHost = 'gateway.sandbox.push.apple.com';
    $apnsHost = 'gateway.push.apple.com';
    $apnsPort = 2195;
    $pem_path = dirname(__FILE__);  
    $pem_path = $pem_path .'\cert';
    $apnsCert = $pem_path.'\apns_cer.pem';

    echo $apnsCert."<br/>"; 
    $streamContext = stream_context_create();
    stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);

    $apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);

    if($apns) {
        echo "Connection Established<br/>";

        $payload = array();
        //$payload['aps'] = array('alert' => 'BiiMe finds product for you', 'badge' => $badge, 'sound' => 'default');
        //$payload = get_payload_message('BiiMe finds product for you',$badge);
        //$payload['server'] = array('serverId' => $serverId, 'name' => $serverName);
        //$payload = json_encode($payload);

        $payload = get_payload_message('BiiMe finds product for you',$badge);
        $apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $deviceToken)) . chr(0) . chr(strlen($payload)) . $payload;

        echo $apnsMessage."<BR/>";

        $fwrite = fwrite($apns, $apnsMessage);  
        echo $fwrite." bytes written<BR/>"; 
    } else {
        echo "Connection fail<br/>";
    }

    //socket_close($apns);  
    fclose($apns);
}

function get_payload_message($message_text,$badge,$sound='default')
{
    $PAYLOAD_MAXIMUM_SIZE = 256;

    $payload['aps'] = array("alert" => "$message_text", 'badge' => $badge, 'sound' => $sound);
    $payload = json_encode($payload);

    $nJSONPayloadLen = strlen($payload);
    if($nJSONPayloadLen > $PAYLOAD_MAXIMUM_SIZE)
    {
        $nTextLen = strlen($message_text);
        if($nJSONPayloadLen - $nTextLen <= $PAYLOAD_MAXIMUM_SIZE)
        {
            $badge_count = substr($message_text, 0, $nTextLen - ($nJSONPayloadLen - $PAYLOAD_MAXIMUM_SIZE));
            $payload  = get_payload_message($message_text);
        }
    }
    return  $payload;
}

Iphone side i added:

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


    NSLog(@"It comes<<<<<<<<<<<<<---------------------------------------");
    NSString *str = [NSString 
                     stringWithFormat:@"Device Token=%@",deviceToken];
    NSLog(str);
    NSString *token = [NSString stringWithFormat:deviceToken];
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    [prefs setObject:token forKey:@"deviceId"];
}

- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err { 
    NSLog(@"It comes with error---------------------------->>>>>>>>>>>>>>");
    NSString *str = [NSString stringWithFormat: @"Error: %@", err];
    NSLog(str);    
    NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
    [prefs setObject:str forKey:@"deviceId"];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

    for (id key in userInfo) {
        NSLog(@"key: %@, value: %@", key, [userInfo objectForKey:key]);
    }    

}

also i use:

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


    UIImageView *loading = [[UIImageView alloc] initWithFrame:CGRectMake(0, 20, 320, 460)];
    [loading setImage:[UIImage imageNamed:@"Default.png"]];
    [window addSubview:loading];
    [loading release];

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

This is my whole code that used:

iPhone Log shows while Device is Connected:

2012-02-03 19:51:32.872 BiiMe[7544:707] It comes<<<<<<<<<<<<<---------------------------------------
2012-02-03 19:51:32.873 BiiMe[7544:707] Device Token=<26d906c5 c273446d 5f40d2c1 73ddd3f6 869b2666 b1c7afd5 173d69b6 629def70>

all times server side:
Connection Established

What is missing by me..? or what should i implemented in my code:

your answer will help me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T06:11:18+00:00Added an answer on May 29, 2026 at 6:11 am

    use this code in didFinishLaunchingWithOption in AppDelegete

    [[UIApplication sharedApplication]
         registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
                                             UIRemoteNotificationTypeSound |
                                             UIRemoteNotificationTypeAlert)];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

while i'm using push notification in iphone with local server(used php), not able to
I am implementing C2DM for push notification in an android application, it need at
I'm implementing typical server-push (comet) application. I'm choosing between two options: the longpoll XHR
In my application I am implementing the Push Notification Service. I have a Content
BOSH (Bidirectional-streams Over Synchronous HTTP) is a sneaky way of implementing 2-way client-server communication
I've been implementing the push service to my application, and I've been thinking about
In my application i used Urban Airship for push Notification, But Urban Airship push
I am implementing a push notification functionality for my app and everything is running
Need help for implementing PUSH notification in android. wanted to know from which android
I am trying to use Google c2dm for implementing an push notification for Android.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.