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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:54:57+00:00 2026-06-14T13:54:57+00:00

Sometimes when I try to inject JS script into UIWebView just after Facebook iOS

  • 0

Sometimes when I try to inject JS script into UIWebView just after Facebook iOS login flow is completed, my iOS app gets frozen during fast-app-switch (from Safari to my app).

In the XCode console I get this error message:

failed to return after waiting 10 seconds. main run loop
mode:kCFRunLoopDefaultMode…

Sometimes the app doesn’t get frozen but the error message appears all the same.

I worked this around by running the JS injection code after an interval of 1 second. I implemented it as follows:

In the callback for FB session changes, I invoke my JS callback in 1 second using NSObject‘s performSelector:withObject:afterDelay: method. Here is my code sample:

/*
 * Callback for session changes.
*/
- (void)sessionStateChanged:(FBSession *)session state:(FBSessionState) state error:(NSError   *)error
{
  switch (state) {
    case FBSessionStateOpen:
      if (!error) {
        // We have a valid session
        [self performSelector:@selector(jsCallback:) withObject:session afterDelay:1];
      }
    break;

  // the rest of the method is omitted
}

- (void)jsCallback:(FBSession *)session {
     UIWebView *webView = ...
     NSString *jsScript = ...
     [webView stringByEvaluatingJavaScriptFromString:jsScript];
}

It works but I’m concerned that it is not a reliable solution. For example, in some situations 1 second might not be enough.

Any ideas how to achieve the same effect in a more reliable way?

  • 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-14T13:54:58+00:00Added an answer on June 14, 2026 at 1:54 pm

    Well, it turned out to be simple. I made use of UIApplicationState, like so:

    /*
     * Callback for session changes.
    */
    - (void)sessionStateChanged:(FBSession *)session state:(FBSessionState) state error:      (NSError   *)error
    {
      switch (state) {
        case FBSessionStateOpen:
          if (!error) {
            // We have a valid session
            UIApplicationState appState = [[UIApplication sharedApplication] applicationState];
    
            NSLog(@"We have a valid session, app state: %u",appState);
    
            if (UIApplicationStateActive == appState){
                [self jsCallback:session];
            } else {
                self.fbSessionJustOpened = YES;
            }
          }
        break;
    
        // the rest of the method is omitted
    }
    

    In UIApplicationDelegate‘s applicationDidBecomeActive method:

    - (void)applicationDidBecomeActive:(UIApplication *)application
    {  
        if (self.isFbSessionJustOpened){
            self.fbSessionJustOpened = NO; // reset flag to NO        
            [self jsCallback:[FBSession activeSession]];
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using facebook sdk 3.0.8 for ios. when i try to login with facebook
When I try to output some data into a text file using FasterCSV, sometimes
I try to deploy my app and sometimes get this error: Failure [INSTALL_FAILED_CONTAINER_ERROR] I
Sometimes when I try to run an app on iPad, via XCode, I receive
at first I would like to try to explain my plan: Sometimes I just
Sometimes when i try to register for C2DM, I get SERVICE_NOT_AVAILABLE error. I used
Sometimes when i try to build/compile a downloaded source, i get following warning: ld:
I notice that sometimes when I try to override a CSS rule, browser does
When,i try to assign null value to my pointer,it sometimes crashes on that line.
I got a little problem. Sometimes, when I try to call the following code,

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.