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

  • Home
  • SEARCH
  • 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 7546917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:19:20+00:00 2026-05-30T09:19:20+00:00

Similar question here: jQueryMobile, Phonegap and Device Token – iOS The scenario is, I

  • 0

Similar question here: jQueryMobile, Phonegap and Device Token – iOS

The scenario is, I have this PhoneGap web based application, and the native iOS help me registered the device on APN and I received the device token in my server database.

Question 1: How do you associate a registered user (through the UIWebView) to this device token using PhoneGap?

  • What’s in my mind now is to write a custom plugin and pass the device token along during user registration. Is there any better alternative?

Question 2: Since device_token can be changed from time to time, how should I re-link this user to this device_token?

  • Perhaps whenever the user login, I do a window.plugins.PluginName.getDeviceToken and sync it?
  • {user_id:123, old_device_token: 'xxxx..', new_device_token: 'xxx...'}?

Fyi, this application is built for an event and the client has requested people to people messaging on this mobile app. How do you push a new message notification to “John Doe” when he received a message from his friend? – Question is how to link “John Doe” to a specific device_token?

This could not be too iOS specific as this application has to be deployed on Android as well (C2DM).

Any help is welcomed!

Edit: Possible solution?

Restless research emerges this possible solution:

  1. [Native] Application started – APN registration started and device_token is received
  2. [Native] Store this device_token into local store (CoreData/SqlLite or Property Lists?) and send it to server to do device_token registration
  3. [WebView] Whenever a user is login or signup, this device_token will be queried through PhoneGap, hashed and sent over to the server to do a sign in, comparison and link up.

Any unforeseen scenario is problematic?

EDIT: Answer

I have my complete working solution posted in the answer. Check it out here: https://stackoverflow.com/a/9628592/534862

  • 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-30T09:19:22+00:00Added an answer on May 30, 2026 at 9:19 am

    Ok, I finally made a plugin that seems to work

    1 – Make sure your PhoneGap Xcode project has been updated for the iOS 4 SDK.

    2 – Create a PushToken folder in your Plugins folder add the following PushToken.m and PushToken.h files to it and then drag the folder to the Plugin folder in XCode, using “Create groups for any added folders”

    3 – Add the PushToken.js files to your www folder on disk, and add reference(s) to the .js files as tags in your html file(s)

    4 – Add new entry with key PushToken and string value PushToken to Plugins in PhoneGap.plist

    PushToken.h

    #import <Foundation/Foundation.h>
    #import <PhoneGap/PGPlugin.h>
    
    @interface PushToken : PGPlugin{
    
        NSString* callbackID;  
    }
    
    @property (nonatomic, copy) NSString* callbackID;
    
    - (void) getToken:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
    
    @end
    

    PushToken.m

    #import "PushToken.h"
    #import "AppDelegate.h"
    
    @implementation PushToken
    
    @synthesize callbackID;
    
    -(void)getToken:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options  {
        self.callbackID = [arguments pop];
    
        NSString *token = ((AppDelegate *)[[UIApplication sharedApplication] delegate]).token;
        PluginResult* pluginResult = [PluginResult resultWithStatus:PGCommandStatus_OK messageAsString:[token stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    
        if(token.length != 0)
        {
            [self writeJavascript: [pluginResult toSuccessCallbackString:self.callbackID]];
        }else {    
            [self writeJavascript: [pluginResult toErrorCallbackString:self.callbackID]];
        }
    }
    
    @end
    

    PushToken.js

    var PushToken = {
        getToken: function(types, success, fail) {
            return PhoneGap.exec(success, fail, "PushToken", "getToken", types);
        }
    };
    

    How to use

    PushToken.getToken(     
        ["getToken"] ,           
        function(token) {
            console.log("Token : "+token); 
        },
        function(error) {
            console.log("Error : \r\n"+error);      
        }
    );
    

    AppDelegate.h

    @interface AppDelegate : PhoneGapDelegate {
        NSString* invokeString;
        NSString* token;
    }
    
    @property (copy)  NSString* invokeString;
    @property (retain, nonatomic) NSString* token;
    

    AppDelegate.m

    - (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
    {
        self.token = [[[[deviceToken description]
                             stringByReplacingOccurrencesOfString: @"<" withString: @""]
                            stringByReplacingOccurrencesOfString: @">" withString: @""]
                           stringByReplacingOccurrencesOfString: @" " withString: @""];
    
        NSLog(@"My token is: %@", self.token);
    }
    

    I made it work on PhoneGap 1.1

    Hope this helps

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

Sidebar

Related Questions

Similar question here but this is slightly different... I have two tables that I
I can't resolve this issue, I found a similar question here but: setting the
This is a question similar to a question here . I wonder is there
This is a similar question to this one here . Given a list of
I ask similar question here I use this sample to implement namedpipes in win
I saw this similar question here but can't figure out how to use Contains
I found a similar question here, but didn't help me. I basically have apache
I have asked a similar question here and got some answers, so first of
I ask similar question here but in this question I use another implementation, exactly
I have found a similar question here , but my intent is little different.

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.