-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChatDemoAppDelegate.m
executable file
·170 lines (127 loc) · 4.56 KB
/
ChatDemoAppDelegate.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
//
// ChatDemoAppDelegate.m
// ChatDemo
//
// Created by Charlene Jiang on 10/10/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "ChatDemoAppDelegate.h"
#import "ChatDemoViewController.h"
#import "LoginViewController.h"
#import <UIKit/UIKit.h>
NSString *const BSSessionStateChangedNotification = @"com.facebook.BlabSay:BSSessionStateChangedNotification";
@implementation ChatDemoAppDelegate
@synthesize window = _window;
@synthesize viewController = _viewController;
@synthesize viewController2 = _viewController2;
- (NSDictionary*)parseURLParams:(NSString *)query {
NSArray *pairs = [query componentsSeparatedByString:@"&"];
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
for (NSString *pair in pairs) {
NSArray *kv = [pair componentsSeparatedByString:@"="];
if ([kv count] > 1) {
NSString *val = [[kv objectAtIndex:1]
stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[params setObject:val forKey:[kv objectAtIndex:0]];
}
}
return params;
}
- (void)sessionStateChanged:(FBSession *)session
state:(FBSessionState) state
error:(NSError *)error
{
switch (state) {
case FBSessionStateOpen:
// We have a valid session
NSLog(@"User session found");
//added FIX
// [FBSession.activeSession closeAndClearTokenInformation];
break;
case FBSessionStateClosed:
break;
case FBSessionStateClosedLoginFailed:
[FBSession.activeSession closeAndClearTokenInformation];
break;
default:
break;
}
if (error) {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Error"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
// Ask for permissions for publishing, getting info about uploaded
// custom photos.
NSArray *permissions = [NSArray arrayWithObjects:
@"publish_actions",
nil];
return [FBSession openActiveSessionWithPermissions:permissions
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
[self sessionStateChanged:session
state:state
error:error];
}];
}
- (void) closeSession
{
[FBSession.activeSession closeAndClearTokenInformation];
}
#pragma mark - Personalization methods
/*
* Makes a request for user data and invokes a callback
*/
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[FBProfilePictureView class];
[FBPlacePickerViewController class];
[FBFriendPickerViewController class];
[self.window setBackgroundColor:[UIColor blackColor]];
self.window.rootViewController = self.viewController2;
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
if (FBSession.activeSession.state == FBSessionStateCreatedOpening)
{
[FBSession.activeSession close]; // so we close our session and start over
}
}
- (void)applicationWillTerminate:(UIApplication *)application
{
[FBSession.activeSession close];
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
{
return [FBSession.activeSession handleOpenURL:url];
}
- (void)dealloc
{
[_window release];
[_viewController release];
[_viewController2 release];
[super dealloc];
}
@end