forked from GMaxera/QtFacebook
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqfacebook_ios_sdk4.mm
More file actions
221 lines (189 loc) · 8.22 KB
/
qfacebook_ios_sdk4.mm
File metadata and controls
221 lines (189 loc) · 8.22 KB
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/* ************************************************************************
* Copyright (c) 2014 GMaxera <gmaxera@gmail.com> *
* *
* This file is part of QtFacebook *
* *
* QtFacebook is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* ********************************************************************** */
#ifdef QFACEBOOK_SDK_4
#include "qfacebook.h"
//#import "FacebookSDK/FacebookSDK.h"
#import "UIKit/UIKit.h"
#include <FBSDKCoreKit/FBSDKCoreKit.h>
#include <QString>
#include <QPixmap>
#include <QByteArray>
#include <QBuffer>
#ifndef QFACEBOOK_NOT_DEFINE_IOS_URL_HANDLER
/*! Override the application:openURL UIApplicationDelegate adding
* a category to the QIOApplicationDelegate.
* The only way to do that even if it's a bit like hacking the Qt stuff
* See: https://bugreports.qt-project.org/browse/QTBUG-38184
*/
@interface QIOSApplicationDelegate
@end
//! Add a category to QIOSApplicationDelegate
@interface QIOSApplicationDelegate (QFacebookApplicationDelegate)
@end
//! Now add method for handling the openURL from Facebook Login
@implementation QIOSApplicationDelegate (QFacebookApplicationDelegate)
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString*) sourceApplication annotation:(id)annotation {
#pragma unused(application)
#pragma unused(sourceApplication)
#pragma unused(annotation)
NSLog(@"error:%@",@"Facebook handled url");
return [[FBSession activeSession] handleOpenURL:url];
}
@end
#endif
using namespace sdkbox;
class QFacebookPlatformData {
public:
QFacebook* qFacebook;
// void sessionStateHandler(FBSession* session, FBSessionState fstate, NSError* error) {
// if (error) {
// NSLog(@"error:%@",error);
// }
// QStringList grantedList;
// switch( fstate ) {
// case FBSessionStateCreated:
// qFacebook->onFacebookStateChanged( QFacebook::SessionCreated, QStringList() );
// break;
// case FBSessionStateCreatedTokenLoaded:
// qFacebook->onFacebookStateChanged( QFacebook::SessionCreatedTokenLoaded, QStringList() );
// break;
// case FBSessionStateCreatedOpening:
// qFacebook->onFacebookStateChanged( QFacebook::SessionCreatedTokenLoaded, QStringList() );
// break;
// case FBSessionStateOpen:
// for( NSString* perm in [session permissions] ) {
// grantedList.append( QString::fromNSString(perm) );
// }
// qFacebook->onFacebookStateChanged( QFacebook::SessionOpen, grantedList );
// break;
// case FBSSDKessionStateOpenTokenExtended:
// for( NSString* perm in [session permissions] ) {
// grantedList.append( QString::fromNSString(perm) );
// }
// qFacebook->onFacebookStateChanged( QFacebook::SessionOpenTokenExtended, grantedList );
// break;
// case FBSessionStateClosedLoginFailed:
// qFacebook->onFacebookStateChanged( QFacebook::SessionClosedLoginFailed, QStringList() );
// break;
// case FBSessionStateClosed:
// qFacebook->onFacebookStateChanged( QFacebook::SessionClosed, QStringList() );
// break;
// }
// }
//! subset of requestPermissions that only allow reading from Facebook
NSMutableArray* readPermissions;
//! subset of requestPermissions that allow writing to Facebook
NSMutableArray* writePermissions;
};
void QFacebook::initPlatformData() {
appID = QString::fromNSString([FBSDKSettings appID]);
displayName = QString::fromNSString( [FBSDKSettings displayName] );
data = new QFacebookPlatformData();
data->qFacebook = this;
data->readPermissions = [[NSMutableArray alloc] init];
data->writePermissions = [[NSMutableArray alloc] init];
PluginFacebook::setListener(this);
// [[FBSession activeSession]
// setStateChangeHandler:^(FBSession* session, FBSessionState state, NSError* error) {
// data->sessionStateHandler(session, state, error);
// }];
// data->sessionStateHandler( [FBSession activeSession], [[FBSession activeSession] state], NULL );
}
void QFacebook::login() {
PluginFacebook::login();
}
bool QFacebook::autoLogin() {
std::vector<std::string> v = {"public_profile", "user_friends", "email" };
PluginFacebook::login(v);
return false;
}
void QFacebook::close() {
PluginFacebook::logout();
}
void QFacebook::requestMe() {
}
void QFacebook::requestPublishPermissions() {
sdkbox::PluginFacebook::requestPublishPermissions({FB_PERM_PUBLISH_POST});
}
void QFacebook::publishPhoto(QString photoUrl, QString message) {
sdkbox::FBShareInfo info;
info.type = sdkbox::FB_PHOTO;
info.title = message.toStdString();
info.image = photoUrl.toStdString();
sdkbox::PluginFacebook::share(info);
}
void QFacebook::publishPhoto( QPixmap photo, QString message ) {
}
void QFacebook::publishPhotosViaShareDialog(QVariantList photos)
{
qDebug() << "Publish Photos" << photos.size();
}
void QFacebook::publishPhotoViaShareDialog(QString photo_url, QString caption) {
}
void QFacebook::publishLinkViaShareDialog( QString linkName, QString link, QString imageUrl, QString caption, QString description ) {
}
void QFacebook::requestMyFriends() {
// Issue a Facebook Graph API request to get your user's friend list
PluginFacebook::fetchFriends();
}
void QFacebook::inviteFriends(QString appId,QString imgUrl){
PluginFacebook::inviteFriends(appId.toStdString(), imgUrl.toStdString());
}
void QFacebook::setAppID( QString appID ) {
if ( this->appID != appID ) {
this->appID = appID;
// [FBSDKSettings setDefaultAppID:(this->appID.toNSString())];
emit appIDChanged( this->appID );
}
}
void QFacebook::setDisplayName( QString displayName ) {
if ( this->displayName != displayName ) {
this->displayName = displayName;
// [FBSettings setDefaultDisplayName:(this->displayName.toNSString())];
emit displayNameChanged( this->displayName );
}
}
void QFacebook::setRequestPermissions( QStringList requestPermissions ) {
this->requestPermissions = requestPermissions;
emit requestPermissionsChanged( this->requestPermissions );
}
void QFacebook::addRequestPermission( QString requestPermission ) {
if ( !requestPermissions.contains(requestPermission) ) {
// add the permission
requestPermissions.append( requestPermission );
emit requestPermissionsChanged(requestPermissions);
}
}
QString QFacebook::getAccessToken() {
return QString::fromStdString(PluginFacebook::getAccessToken());
}
QString QFacebook::getExpirationDate() {
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
NSLocale* enUSPOSIXLocale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
[dateFormatter setLocale:enUSPOSIXLocale];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"];
NSDate* date = [[FBSDKAccessToken currentAccessToken] expirationDate] ;
return QString::fromNSString( [dateFormatter stringFromDate:date] );
}
void QFacebook::onApplicationStateChanged(Qt::ApplicationState state) {
// if ( state == Qt::ApplicationActive ) {
// [[FBSession activeSession] handleDidBecomeActive];
// }
}
#endif