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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:50:54+00:00 2026-06-12T05:50:54+00:00

Developing an app for iOS, I need to know how to have instanced and

  • 0

Developing an app for iOS, I need to know how to have instanced and available an object created when user authenticates.

I am using OAuth2 method properly implementing gtm-oauth2 framework. The user entries, sees the login form displayed in a web view and correctly authenticates. In that moment, as detailed in the documentation, I go like this:

if (error != nil){
    // Do whatever to control the error
}
else
{
    // Authentication succeeded

    // Assign the access token to the instance property for later use
    self.accessToken = myAuth.accessToken;
    [myAuth setShouldAuthorizeAllRequests:YES];
    [self setAuth:myAuth];

    // Display the access token to the user
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Authorization Succeeded"
                                                        message:[NSString stringWithFormat:@"Access Token: %@", myAuth.accessToken]
                                                       delegate:self
                                              cancelButtonTitle:@"Dismiss"
                                              otherButtonTitles:nil];
    [alertView show];
}

Later, in the same controller, I use the self.auth object like this to access my API once the user has authenticated:

[request setURL:getCartsURL];
[request setValue:self.accessToken forHTTPHeaderField:@"Authorization"];
[self.auth authorizeRequest:request
          completionHandler:^(NSError *error) {
              NSString *output = nil;
              if (error) {
                  output = [error description];
              } else {
                  // Synchronous fetches like this are a really bad idea in Cocoa applications
                  //
                  // For a very easy async alternative, we could use GTMHTTPFetcher
                  NSURLResponse *response = nil;
                  NSData *data = [NSURLConnection sendSynchronousRequest:request
                                                       returningResponse:&response
                                                                   error:&error];

                  if (data) {
                      // API fetch succeeded
                      output = [[NSString alloc] initWithData:data
                                                     encoding:NSUTF8StringEncoding];

                      SBJsonParser *jsonParser = [SBJsonParser new];

                      // Parse the JSON into an Object
                      id parsed = [jsonParser objectWithString:output];

                      NSArray *arrayResponse = [[NSArray alloc] initWithArray:parsed];

                  } else {
                      // fetch failed
                      output = [error description];
                  }
              }
          }];

So far, I have been using a local instance of self.auth object, what happens to be insufficient if I want to have that object globally accessed from any point of the whole app. Ok for the init view controller, but not for the whole app.

I think I can somehow access this first view controller to get the object anytime I want it. But I guess we have better methods to have it globally instanced and accessible from any point of the app.

Can you please help me with this?

Thanks a lot.

  • 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-12T05:50:56+00:00Added an answer on June 12, 2026 at 5:50 am

    You should use a Singleton. Here is a nice article on how to set one up.

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

Sidebar

Related Questions

I'm developing an iOS app, but i need to identify the user who made
I'm developing an iOS app using Core Plot headers. I have different UI for
I'm developing a native mobile app for Android and iOS using PhoneGap.I have a
I am developing an IOS app. I need a functionality that includes undo and
We are now developing a social news feed iOS app, and we need to
I'm developing an iOS app. Its working properly on simulator. I'm using phonegap and
I am developing an iPhone app in iOS 5. I am using UIImagePickerController to
I'm developing Mac app for free. In iOS , we need developer account to
I'm developing an iOS 4 app with latest SDK and XCode 4. I need
I'm currently in the planning stages of developing an iOS app, and I need

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.