How to manage openUrl method inside called application in iOS? - ios

I suppose that this is duplicate but I can not figure it out.
I have to call other app from my iOS app using openUrl method. After finishing its work the other app must return to my app using the same method. I figure out how to call the other App and its open my App too. My problem is how to intercept the return to my App. I need to check the value from query string.
I find that method handleOpenURL intercepts return and I can handle my query string.
And here I am stuck - how to use that info inside my ViewController? I set breakpoint in viewDidLoad but it was not hit. Which method I have to use?
EDIT:
My Code is (inside AppDelegate):
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
NSLog(#"url recieved: %#", url);
NSLog(#"query string: %#", [url query]);
NSLog(#"host: %#", [url host]);
NSLog(#"url path: %#", [url path]);
NSDictionary *dict = [self parseQueryString:[url query]];
NSLog(#"query dict: %#", dict);
return YES;
}
- (NSDictionary *)parseQueryString:(NSString *)query {
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithCapacity:6];
NSArray *pairs = [query componentsSeparatedByString:#"&"];
for (NSString *pair in pairs) {
NSArray *elements = [pair componentsSeparatedByString:#"="];
NSString *key = [[elements objectAtIndex:0] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *val = [[elements objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[dict setObject:val forKey:key];
}
return dict;
}
Which works fine.
Inside my ViewController (VC):
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self setNeedsStatusBarAppearanceUpdate];
// Instantiate App singleton
singApp = [PESsingApplication sharedInstance];
#try {
// Localize resources using currently saved setting for language
[self setLocalizedResources];
// Init visual buttons
[self baseInit];
// Add code for keyboard management
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardShow:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardHide:)
name:UIKeyboardWillHideNotification
object:nil];
CGRect screenRect = [[UIScreen mainScreen] bounds];
_screenHeight = screenRect.size.height;
_screenWidth = screenRect.size.width;
}
#catch (NSException *exception) {
[self throwUnknownException:exception];
}
}
-(UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleLightContent;
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
My url:
URL identifier: xx.mydomain.MyUrlScheme
URL shcemes: MyUrlScheme
I have breakpoints inside my VC (on each of the method shown above).
I use following string to call other app: #"otherApp://openApp?param1=value1&callbackUrl=MyUrlScheme";
They call me from the otherApp using callbackUrl param.

You need to make your own custom URL, please look below
How to implement Custom URL Scheme
Defining your app's custom URL scheme is all done in the Info.plist file. Click on the last line in the file and then click the "+" sign off to the right to add a new line. Select URL Types for the new item. Once that's added, click the grey arrow next to "URL Types" to show "Item 0". Set your URL identifier to a unique string - something like com.yourcompany.yourappname.
After you've set the URL identifier, select that line and click the "+" sign again, and add a new item for URL Schemes. Then click the grey arrow next to "URL Schemes" to reveal "Item 0". Set the value for Item 0 to be your URL scheme name.
Handling Custom URL Calls
In order for your app to respond when it receives a custom URL call, you must implement the application:handleOpenURL method in the application delegate class:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
// your code
}
Parsing the Custom URL
There are several parts to a URL:
scheme://host/path?query
The parts to the URL can be retrieved through the NSURL object that is passed into the application:handleOpenURL method. If you have a fairly simple URL naming scheme and want to allow access to specific pages/keys, you can just use the host name:
Custom URL Value of [url host]:
myapp://page1 page1
myapp://page2 page2
myapp://otherPage otherPage
To pass data into your app, you'll want to use the query string. Here's a simple method for parsing the query string from the url:
- (NSDictionary *)parseQueryString:(NSString *)query {
NSMutableDictionary *dict = [[[NSMutableDictionary alloc] initWithCapacity:6] autorelease];
NSArray *pairs = [query componentsSeparatedByString:#"&"];
for (NSString *pair in pairs) {
NSArray *elements = [pair componentsSeparatedByString:#"="];
NSString *key = [[elements objectAtIndex:0] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *val = [[elements objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[dict setObject:val forKey:key];
}
return dict;
}
Testing The Custom URL
You can easily test your URL scheme in the simulator. Just add a test button to one of your views, and implement the IBAction method for it as follows:
- (IBAction)getTest:(id)sender {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"myappscheme://test_page/one?token=12345&domain=foo.com"]];
}
Then in your app delegate, implement the application:handleOpenURL method:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
NSLog(#"url recieved: %#", url);
NSLog(#"query string: %#", [url query]);
NSLog(#"host: %#", [url host]);
NSLog(#"url path: %#", [url path]);
NSDictionary *dict = [self parseQueryString:[url query]];
NSLog(#"query dict: %#", dict);
return YES;
}
Finally if you are looking method to receive your data anywhere you can use this two scenario.
You can simple use Local notification or NSUserDefault
NSUserDefault
- (BOOL)application:(UIApplication *)application handleopenURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
NSUserDefaults *userDefaults=[[NSUserDefaults alloc] init];
[userDefaults synchronize];
NSString *status = [defaults stringForKey:#"any status"];
}
Local notification
- (BOOL)application:(UIApplication *)application handleopenURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
localNotif.userInfo = [NSDictionary dictionaryWithObjectsAndKeys:VAL, #"value", nil];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
}

If your viewDidLoad is not called perfectly try in viewWillAppear or viewDidAppear method.
For example purpose:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
NSDictionary *dict = [self parseQueryString:[url query]];
NSLog(#"query dict: %#", dict);
// add dictionary to standardUserDefaults for saving purpose, like
[[NSUserDefaults standardUserDefaults] setObject:dict forKey:#"DicKey"];
[[NSUserDefaults standardUserDefaults] synchronize];
// add code for navigation/present view controller
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main"
bundle: nil];
YourViewController *yourController = (YourViewController *)[mainStoryboard
instantiateViewControllerWithIdentifier:#"YourViewControllerID"];
self.window.rootViewController = yourController;
return YES;
}
for retrieve
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSMutableDictionary *mutableRetrievedDictionary = [[[NSUserDefaults standardUserDefaults] objectForKey:#"DicKey"] mutableCopy];
// here parse the dictionary and do your work here, when your works is over
// remove the key of standardUserDefaults
[[NSUserDefaults standardUserDefaults] removeObjectForKey:#"DicKey"];
[[NSUserDefaults standardUserDefaults] synchronize];
}

Store the status from other app in NSUserdefaults, when the ViewController of your app launches fetch the status into a NSString from NSUserdefaults and rise it as an alert.
Call the handleopenURL in appdelegate
- (BOOL)application:(UIApplication *)application handleopenURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
NSUserDefaults *defaults=[[NSUserDefaults alloc] init];
[defaults synchronize];
NSString *status = [defaults stringForKey:#"status string from other app"];
}

Related

Why is Apple Watch not syncing with App delegate & NSUbiquitousValueStore?

I run this in my View Controller:
NSString *indexV = [NSString stringWithFormat:#"%d", index];
[[NSUbiquitousKeyValueStore defaultStore] setString:indexV forKey:#"index"];
[[NSUbiquitousKeyValueStore defaultStore] synchronize];
indexV = [[NSUbiquitousKeyValueStore defaultStore] stringForKey:#"index"];
NSLog(#"index V: %#", indexV);
Then quit the app.
In my AppDelegate I have:
- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void (^)(NSDictionary *))reply {
NSString *indexV = [[NSUbiquitousKeyValueStore defaultStore] stringForKey:#"index"];
NSLog(#"indexV: %#", indexV);
NSDictionary *d = #{#"index" : indexV};
reply(d);
In my InterfaceController I have:
- (void)awakeWithContext:(id)context {
[super awakeWithContext:context];
[self sync];
- (void)sync {
[WKInterfaceController openParentApplication:#{#"give" : #"give"} reply:^(NSDictionary *replyInfo, NSError *error) {
NSLog(#"index: %#", replyInfo[#"index"]);
if (replyInfo[#"index"]) {
index = [replyInfo[#"index"] intValue];
In the iPhone app, I see the log where index is being set to an integer > 0.
Why is this string not synchronizing between apps?
I am able to send arrays ok.
Yes I have app groups configured, which is how - (void)application:(UIApplication *)application handleWatchKitExtensionRequest: .. will respond at all.
But when I run the Apple Watch app, index always comes through as #"0".

Handling Dropbox authentication response

Dropbox documentation explains by default the response for authentication gets fired into Appdelegate.m
How do I make the same fire my own class's delegate?
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url
sourceApplication:(NSString *)source annotation:(id)annotation {
if ([[DBSession sharedSession] handleOpenURL:url]) {
if ([[DBSession sharedSession] isLinked]) {
NSLog(#"App linked successfully!");
// At this point you can start making API calls
}
return YES;
}
// Add whatever other url handling code your app requires here
return NO;
}
In info plist url type --> in url schemes just add db-YourAppKey this method will get called.
This method is getting called automatically. I hope you already created app from dropbox developer site and get the appKey and appSecret. Use this code in app delegate NSString* appKey = #"";
NSString* appSecret = #"";
NSString *root = kDBRootDropbox;
NSString* errorMsg = nil;
if ([appKey rangeOfCharacterFromSet:[[NSCharacterSet alphanumericCharacterSet] invertedSet]].location != NSNotFound) {
errorMsg = #"Make sure you set the app key correctly in DBRouletteAppDelegate.m";
} else if ([appSecret rangeOfCharacterFromSet:[[NSCharacterSet alphanumericCharacterSet] invertedSet]].location != NSNotFound) {
errorMsg = #"Make sure you set the app secret correctly in DBRouletteAppDelegate.m";
} else if ([root length] == 0) {
errorMsg = #"Set your root to use either App Folder of full Dropbox";
} else {
NSString *plistPath = [[NSBundle mainBundle] pathForResource:#"Info" ofType:#"plist"];
NSData *plistData = [NSData dataWithContentsOfFile:plistPath];
NSDictionary *loadedPlist =
[NSPropertyListSerialization
propertyListFromData:plistData mutabilityOption:0 format:NULL errorDescription:NULL];
NSString *scheme = [[[[loadedPlist objectForKey:#"CFBundleURLTypes"] objectAtIndex:0] objectForKey:#"CFBundleURLSchemes"] objectAtIndex:0];
if ([scheme isEqual:#"db-APP_KEY"]) {
errorMsg = #"Set your URL scheme correctly in DBRoulette-Info.plist";
}
}
DBSession* session =
[[DBSession alloc] initWithAppKey:appKey appSecret:appSecret root:root];
session.delegate = self; // DBSessionDelegate methods allow you to handle re-authenticating
[DBSession setSharedSession:session];
[DBRequest setNetworkRequestDelegate:self];
// [[DBSession sharedSession]unlinkAll];
if ([[DBSession sharedSession] isLinked])
{
isAccountForDropBox = YES;
}
else{
isAccountForDropBox = NO;
}
//After using this that open url will get call automatically.
These method only respond in AppDelegate.m,you can't use outside it.
To use in your ViewController or any class, you should use post notification
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url
sourceApplication:(NSString *)source annotation:(id)annotation {
if ([[DBSession sharedSession] handleOpenURL:url]) {
if ([[DBSession sharedSession] isLinked]) {
NSLog(#"App linked successfully!");
// Post Notify here
[[NSNotificationCenter defaultCenter] postNotificationName:#"applicationDidLinkWithDropbox" object:self];
}
return YES;
}
// Add whatever other url handling code your app requires here
return NO;
}
Then receive this notification in your class, in a ViewController for example:
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(dropBoxDidLink:)
name:#"applicationDidLinkWithDropbox"
object:nil];
}
- (void) dropBoxDidLink:(NSNotification *)notification {
if ([[notification name] isEqualToString:#"applicationDidLinkWithDropbox"]) {
//Handle your task here
}
}

How to pass the device token from AppDelegate to UIViewController

Hi in my application I'm fetching the device token and I'm passing to my server to send the notification now I want to send the individual notification for the i need to fetch the device token form my UIViewController Please tell is there any possibilities fetching the device token form the Appdelegate or from the UIViewController
My code for fetching the device token in Appdelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeNone)];
return YES;
}
Device Token.
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
const char* data = [deviceToken bytes];
NSMutableString * token = [NSMutableString string];
for (int i = 0; i < [deviceToken length]; i++) {
[token appendFormat:#"%02.2hhX", data[i]];
}
NSString *urlString = [NSString stringWithFormat:#"url?token=%#",token];
NSURL *url = [[NSURL alloc] initWithString:urlString];
NSLog(#"token %#",urlString);
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
NSLog(#"request %# ",urlRequest);
NSData *urlData;
NSURLResponse *response;
urlData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:nil];
NSLog(#"data %#",urlData);
}
I have used the to get the device token please tell me how to pass the device token to my UIViewController or how to fetch the device token from my UIViewController.
Use the NSUserDefaults to store the objects(values), you can access it anywhere.
AppDelegate (setValue) :
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
[[NSUserDefaults standardUserDefaults] setObject: token forKey:#"deviceID"];
[[NSUserDefaults standardUserDefaults]synchronize];
}
UIViewController (getValue) :
[[NSUserDefaults standardUserDefaults] objectForKey:#"deviceID"];
In AppDelegate.m class:
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
NSLog(#"My token is: %#", deviceToken);
NSString *device = [deviceToken description];
device = [device stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:#"<>"]];
device = [device stringByReplacingOccurrencesOfString:#" " withString:#""];
NSLog(#"My device is: %#", device);
[[NSUserDefaults standardUserDefaults] setObject:device forKey:#"MyAppDeviceToken"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
In ViewController class, inside viewDidLoad method:
[super viewDidLoad];
NSString *deviceToken = [[NSUserDefaults standardUserDefaults] objectForKey:#"MyAppDeviceToken"];
NSLog(#"device token in controller: %# ", deviceToken);
This is working perfectly in my device. Happy Coding !! :)
Try this coding in your view did load
NSString* deviceId = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
deviceId = [deviceId stringByReplacingOccurrencesOfString:#"-" withString:#""];
NSLog(#"%#",deviceId);
Declare and define below methods in your delegate file,
#pragma mark - Get / Set Device Token
+ (void)setDeviceToken:(NSString *)token {
if(token) {
[[NSUserDefaults standardUserDefaults] setObject:token forKey:#"DeviceToken"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
}
+ (NSString *)getDeviceToken {
NSString *token = [[NSUserDefaults standardUserDefaults] objectForKey:#"DeviceToken"];
if(token) {
return token;
}
return #"";
}
In -(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken method
call, [AppDelegate setDeviceToken:token]; once you get the token and
Now in project, in any view controller, you can call NSString *token = [AppDelegate getDeviceToken]; to get saved token, here note that, we call it with AppDelegate its name of your delegate file, and we call it with the class name, as we make a class method to set and get a token.
At the time of getting you can check for availability of saved token
NSString *token = [AppDelegate getDeviceToken];
if(token.length) {
// do something
}
You can get appDelegate instance in any view contoller and fetch value from that instance like -
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

iOS custom url scheme

I'm creating an app that uses a custom url scheme, I have it all set up and it works when opening the app up, however, I now want to be able to add a single string to the url so that the person that opens the app can see that string. I'm really struggling with this, can someone help me please?
Here is my code
- (NSDictionary*)parseURLParams:(NSString *)query
{
NSArray *pairs = [query componentsSeparatedByString:#"&"];
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
for (NSString *pair in pairs)
{
NSArray *kv = [pair componentsSeparatedByString:#"="];
NSString *val = [[kv objectAtIndex:1]
stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[params setObject:val forKey:[kv objectAtIndex:0]];
}
return params;
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:#"Send Challenge"])
{
[FBWebDialogs presentRequestsDialogModallyWithSession:nil
message:[NSString stringWithFormat:#"I just scored %i points on this great game, called SumsUp. can you beat it?!", gameScore]
title:nil
parameters:nil
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error)
{
// Error launching the dialog or sending the request.
NSLog(#"Error sending request.");
}
else
{
if (result == FBWebDialogResultDialogNotCompleted)
{
// User clicked the "x" icon
NSLog(#"User canceled request.");
}
else
{
// Handle the send request callback
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
if (![urlParams valueForKey:#"request"])
{
// User clicked the Cancel button
NSLog(#"User canceled request.");
}
else
{
// User clicked the Send button
NSString *requestID = [urlParams valueForKey:#"request"];
NSLog(#"Request ID: %#", requestID);
}
}
}
}];
}
I have got the custom url setup in the P-List.
in my app delegate I have:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
UIAlertView *alertView;
NSString *text = [NSString stringWithFormat: #"url recieved: %#", url];
alertView = [[UIAlertView alloc] initWithTitle:#"" message:text delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
return [FBAppCall handleOpenURL:url sourceApplication:sourceApplication withSession:[PFFacebookUtils session]];
}
I hope this makes sense and somebody can help me. If any more information is required please let me know?
Thanks Graham
I had problem with custom URL Scheme on ios v. 9.x.x. when i tried open Youtube URL by App. I have found interesting fact when i have browsed through network.
iOS 9 requires your app to pre-register application schemes it intends to call.
Open your YourApp-Info.plist file and add the key, LSApplicationQueriesSchemes.
List item under LSApplicationQueriesSchemes, add a
new item with the value youtube (in my case).
<key>LSApplicationQueriesSchemes</key>
<array>
<string>youtube</string>
</array>
My solution is simpler. I hope you will find it useful.
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
{
// Example URL: myapp://myapp.com/showString/yourString
BOOL isMyAppURL = [[url scheme] isEqualToString:#"myapp"];
if (isMyAppURL)
{
NSArray* pathComponents = [url pathComponents];
NSString *command = pathComponents[0];
// Check for showString command.
if ([command isEqualToString:#"showString"])
{
NSString *stringToShow = [pathComponents[1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(#"String to show: %#", stringToShow);
}
}
return isMyAppURL;
}
This should point you to the right direction.

Twitter Authorization Login

I'm using STTwitterto interface with Twitter in an iOS app I'm changing for someone. When I call the twitter authorization page for the first time with the following code:
- (void)newUser
{
[[NetworkManager sharedInstance] resetTwitterAPI];
[[[NetworkManager sharedInstance] twitterAPI] postTokenRequest:^(NSURL *url, NSString *oauthToken) {
[[UIApplication sharedApplication] openURL:url];
} oauthCallback:#"tweepr://twitter_access_token" errorBlock:^(NSError *error) {
NSLog(#"Error %s", __PRETTY_FUNCTION__);
}];
}
* Which, in turn, calls this:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
if (![[url scheme] isEqualToString:#"tweepr"]) {
return NO;
}
NSDictionary *d = [self parametersDictionaryFromQueryString:[url query]];
NSString *token = d[#"oauth_token"];
NSString *verifier = d[#"oauth_verifier"];
[[UserLoadingRoutine sharedRoutine] setOAuthToken:token verifier:verifier];
return YES;
}
* Which finally calls this:
- (void)setOAuthToken:(NSString *)token verifier:(NSString *)verifier
{
[[[NetworkManager sharedInstance] twitterAPI] postAccessTokenRequestWithPIN:verifier successBlock:^(NSString *oauthToken, NSString *oauthTokenSecret, NSString *userID, NSString *screenName) {
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
dict[#"nickname"] = screenName;
dict[#"token"] = oauthToken;
dict[#"secret"] = oauthTokenSecret;
dict[#"user_id"] = userID;
self.userDict = dict;
NSMutableArray *users = [self.availableUsers mutableCopy];
if (![users containsObject:dict]) {
[users addObject:dict];
}
self.availableUsers = [users copy];
[[NSUserDefaults standardUserDefaults] setObject:self.availableUsers forKey:#"availableUsers"];
[[NSUserDefaults standardUserDefaults] synchronize];
[self selectUserWithIdentifier:dict[#"nickname"]];
} errorBlock:^(NSError *error) {
NSLog(#"Error");
}];
}
The twitter authorization page, the first time it comes up, has login and password fields to fill in as shown below at This Screenshot. If I bring the authorization page up again via the above code to authorize under a different user, This Screenshot appears and I need to sign out on the top. Is there a way to do this progmatically?
Append &force_login=1 to the URL string in -[STTwitterOAuth postTokenRequest:oauthCallback:errorBlock:].
Let me know if it works.

Resources