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 374331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:23:42+00:00 2026-05-12T14:23:42+00:00

Is there a sample project showing how to use APNS on the IPhone and

  • 0

Is there a sample project showing how to use APNS on the IPhone and how to set up things? I’m currently looking at the documentation but it would be nice to have some working code to pick apart and see how it all works together?

I can’t seem to find anything using google or in the iphone dev center.

  • 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-12T14:23:43+00:00Added an answer on May 12, 2026 at 2:23 pm

    The worst part about setting up the push notification service is the provisioning. The major stumbling block that I came across was that there is a certificate and a key in the .cer file you download from Apple’s site, I wrote a system service in C# that sent out notifications and the connections kept failing because I had exported the certificate and not the key.

    I don’t recall who originally wrote this, here is a little bit of code in python that helped me out when I was first testing the notification service. I like it because it is very simple and works well during testing.

    import socket, ssl, json, struct
    
    # device token returned when the iPhone application
    # registers to receive alerts
    
    deviceToken = 'XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX' 
    
    thePayLoad = {
         'aps': {
              'alert':'Oh no! Server\'s Down!',
              'sound':'k1DiveAlarm.caf',
              'badge':42,
              },
         'test_data': { 'foo': 'bar' },
         }
    
    # Certificate issued by apple and converted to .pem format with openSSL
    # Per Apple's Push Notification Guide (end of chapter 3), first export the cert in p12 format
    # openssl pkcs12 -in cert.p12 -out cert.pem -nodes 
    #   when prompted "Enter Import Password:" hit return
    #
    theCertfile = 'cert.pem'
    # 
    theHost = ( 'gateway.sandbox.push.apple.com', 2195 )
    
    # 
    data = json.dumps( thePayLoad )
    
    # Clear out spaces in the device token and convert to hex
    deviceToken = deviceToken.replace(' ','')
    byteToken = bytes.fromhex( deviceToken ) # Python 3
    # byteToken = deviceToken.decode('hex') # Python 2
    
    theFormat = '!BH32sH%ds' % len(data)
    theNotification = struct.pack( theFormat, 0, 32, byteToken, len(data), data )
    
    # Create our connection using the certfile saved locally
    ssl_sock = ssl.wrap_socket( socket.socket( socket.AF_INET, socket.SOCK_STREAM ), certfile = theCertfile )
    ssl_sock.connect( theHost )
    
    # Write out our data
    ssl_sock.write( theNotification )
    
    # Close the connection -- apple would prefer that we keep
    # a connection open and push data as needed.
    ssl_sock.close()
    

    There’s also a rails gem called apn_on_rails that seems to work pretty well if you’re developing a rails application, I just saw it today and was able to send out notifications from the console.

    On the iPhone side you’ll just need to call the following to register for all types of notifications:

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

    To receive the device token you’ll need to implement the following delegate methods:

    - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
    
    - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
    

    During testing you can just kick the deviceToken to the console with NSLog, then paste it into the python script above, in production you’ll obviously need to set up some method to get the token to your servers.

    Also, in production you’ll need to query Apple’s feedback service and remove device tokens from users who removed your app.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, so I'm trying to finish our simple project for Data Strcutures but there
There are sample codes on the net for OpenId Client but none for OpenId
Are there any sample applications avaliable that make use of both caliburn and prism?
In iPhone App I want to integrate Google Places Api. Is there any sample
In my current simple project, Copybin , there is some space at the bottom
Is there a sample code available online to get WinRT to determine if its
There was some sample codes in the resource section, explaining some examples, that now
There is a sample code of apple named reachability which tells us the network
There is a sample code which works in a multithreading environment: void CSampleClass::Stop(void) {
There are many sites with instructions on installing ropemacs, but so far I couldn't

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.