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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:30:10+00:00 2026-06-05T13:30:10+00:00

With ios4.x I can use code below to get the message when get the

  • 0

With ios4.x I can use code below to get the message when get the “kCTMessageReceivedNotification” notification

CTTelephonyCenterAddObserver( ct, NULL, callback,NULL,NULL, CFNotificationSuspensionBehaviorHold); 

if ([notifyname isEqualToString:@"kCTMessageReceivedNotification"])//receive message
    {

        NSDictionary *info = (NSDictionary *)userInfo;
        CFNumberRef msgID = (CFNumberRef)[info objectForKey:@"kCTMessageIdKey"];
        int result;
        CFNumberGetValue((CFNumberRef)msgID, kCFNumberSInt32Type, &result);   
        Class CTMessageCenter = NSClassFromString(@"CTMessageCenter");
        id mc = [CTMessageCenter sharedMessageCenter];
        id incMsg = [mc incomingMessageWithId: result];}

But with ios5 I can’t do it as incMsg is nil,so what can i do to get the message?

Thanks

  • 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-06-05T13:30:11+00:00Added an answer on June 5, 2026 at 1:30 pm

    Here’s what I found …

    Just looking at the dumped private APIs, it looks like ChatKit.framework could help. Take a look at
    CKSMSService.h

    or CKMadridService.h for iMessage messages.

    I did quickly attempt to swizzle my own method in, for a couple methods in CKSMSService:

    - (void)_receivedMessage: (id)arg1 replace:(BOOL)arg2 replacedRecordIdentifier:(int)arg3 postInternalNotification:(BOOL)arg4;
    
    - (void)_receivedMessage: (id)arg1 replace:(BOOL)arg2 postInternalNotification:(BOOL)arg3;
    

    but on iOS 5.0.1 I didn’t see either of those get called (maybe my error?). So, I tried to just get the message directly from the sqlite SMS database. Note … I didn’t build the full app, to register for notifications. I’m assuming your code to get the kCTMessageReceivedNotification is ok … it just doesn’t give you the SMS content anymore. So, if you put the following code in your notification handler, you should be able to see the message text:

    - (NSString *) mostRecentSMS  { 
        NSString *text = @"";
    
        sqlite3 *database;
        if(sqlite3_open([@"/private/var/mobile/Library/SMS/sms.db" UTF8String], &database) == SQLITE_OK) {
            sqlite3_stmt *statement;
    
            // iOS 4 and 5 may require different SQL, as the .db format may change
            const char *sql4 = "SELECT text from message ORDER BY rowid DESC";  // TODO: different for iOS 4.* ???
            const char *sql5 = "SELECT text from message ORDER BY rowid DESC";
    
            NSString *osVersion =[[UIDevice currentDevice] systemVersion];         
            if([osVersion hasPrefix:@"5"]) {
                // iOS 5.* -> tested
                sqlite3_prepare_v2(database, sql5, -1, &statement, NULL);
            } else {
                // iOS != 5.* -> untested!!!
                sqlite3_prepare_v2(database, sql4, -1, &statement, NULL);
            }
    
            // Use the while loop if you want more than just the most recent message
            //while (sqlite3_step(statement) == SQLITE_ROW) {
            if (sqlite3_step(statement) == SQLITE_ROW) {
                char *content = (char *)sqlite3_column_text(statement, 0);
                text = [NSString stringWithCString: content encoding: NSUTF8StringEncoding];
                sqlite3_finalize(statement);
            }
    
            sqlite3_close(database);
        }
        return text;
    }    
    

    Now, make sure this app is installed in /Applications/. If you just build this app, and install normally with Xcode, you’ll get a permission denied error opening the sqlite database, because of app sandboxing.

    My code snippet just gets the most recent text content. Here’s an example of doing a little more with the database. Look at the QuerySMS method.

    Also, here’s a link on the database format of sms.db. You can find what else you need in there. Or, just copy the sms.db to your computer, and browse it with something like the Firefox SQLiteManager plugin. Good luck!

    Update: some information from a question I posted on multi-process SQLite thread safety on iOS

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

Sidebar

Related Questions

I can get individual uncompressed frames from the iPhone's camera in iOS4. What i
My current xcode is Xcode 3.2.6. It has iOS4.3. Can I use XCode 3.2.6
I'm guessing this must be new functionality as this code fail on my iOS4
This was working fine before compiling with iOS4.0 and I can't figure out what's
Is it possible to have iOS4 specific code (ie the MKMapView overlays) in an
I have spotted an example in book: iOS4 Programming Cookbook that I can't understand:
How can I perform a run-time check to see if I can use UIGraphicsBeginImageContextWithOptions
I can see with iOS4 you can now tile an image on google maps
I've extensively searched the web, and everything I've found suggests that I can use
I followed below code to establish https connection in my application to fetch some

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.