Quickblox - fetch user friends' avatars and display inside a UITableView - ios

I need to display entire friend list's avatar images inside UITableView.
I could as well ask this into Quickblox forums but seems like their support is less responsive there.
I have read Quickblox documentation but can't find an efficient way of getting user's avatar images. All I see is [QBContent TDownloadFileWithBlobID], but I do not know how to use it.
I am fetching contacts using chatContactListDidChange delegate call like below. Now how can I also get all these users' avatar images also?
Note that friendsArray is my data source for the table view, so ideally I would want to store the avatar images as part of the same array.
- (void)chatContactListDidChange:(QBContactList *)contactList
{
NSLog(#"contact list changed");
NSLog(#"current contact list %#", [QBChat instance].contactList);
[self fetchContacts:[QBChat instance].contactList.contacts];
}
- (void) fetchContacts : (NSArray *) contactArray
{
NSMutableArray * userIDArray = [[NSMutableArray alloc] init];
for (QBContactListItem * contact in contactArray)
{
NSString * userIDString = [NSString stringWithFormat:#"%ld", (unsigned long)contact.userID];
[userIDArray addObject:userIDString];
}
if (!userIDArray.count)
{
return;
}
NSString * requestString = [userIDArray componentsJoinedByString:#","];
[QBUsers usersWithIDs:requestString delegate:self context:#"FetchFriends"];
}
- (void)completedWithResult:(Result *)result context:(void *)contextInfo
{
if([result isKindOfClass:[QBUUserPagedResult class]])
{
NSString * context = (__bridge NSString *)contextInfo;
// Success result
if(result.success)
{
QBUUserPagedResult * pagedResult = (QBUUserPagedResult *)result;
if ([context isEqualToString:#"FetchFriends"])
{
if (friendsArray)
{
[friendsArray removeAllObjects];
}
else
{
friendsArray = [[NSMutableArray alloc] init];
}
QBUUser * user = [pagedResult.users objectAtIndex:0];
//user.blobID
friendsArray addObjectsFromArray:pagedResult.users];
}
}
else
{
NSLog(#"Error getting users: %#", context);
}
}
}

Use QBUUser's fields - customData for public url of user's image and blobID for uploaded blob.
Image --> [QBContent TUploadFile...] --> Getting callback with result (QBCFileUploadTaskResult) --> getting blob (QBCBlob) --> save blob id to user.blobID --> get public url of your image: [currentBlob publicURL] --> save to user.customData --> update user: [QBUsers updateUser...]
Hope it helps you.

Related

Error 403 on Youtube Video Upload IOS

In my project wanna have a flow like this:
Users record short videos -> they upload the videos on my channel -> end
To achive this result i'm trying to work with the new Google APIs Client Library for Objective-C for REST. It has a poor documentation and the examples are for mac only. Anyway after many errors this is my code:
- (void)doAuthWithoutCodeExchange:(OIDServiceConfiguration *)configuration
clientID:(NSString *)clientID
clientSecret:(NSString *)clientSecret {
NSURL *redirectURI = [NSURL URLWithString:kRedirectURI];
// builds authentication request
OIDAuthorizationRequest *request =
[[OIDAuthorizationRequest alloc] initWithConfiguration:configuration
clientId:clientID
clientSecret:clientSecret
scopes:#[ OIDScopeOpenID, OIDScopeProfile ]
redirectURL:redirectURI
responseType:OIDResponseTypeCode
additionalParameters:nil];
// performs authentication request
AppDelegate *appDelegate = (AppDelegate *) [UIApplication sharedApplication].delegate;
[self logMessage:#"Initiating authorization request %#", request];
appDelegate.currentAuthorizationFlow =
[OIDAuthorizationService presentAuthorizationRequest:request
presentingViewController:self
callback:^(OIDAuthorizationResponse *_Nullable authorizationResponse,
NSError *_Nullable error) {
if (authorizationResponse) {
OIDAuthState *authState =
[[OIDAuthState alloc] initWithAuthorizationResponse:authorizationResponse];
[self setAuthState:authState];
[self logMessage:#"Authorization response with code: %#",
authorizationResponse.authorizationCode];
// could just call [self tokenExchange:nil] directly, but will let the user initiate it.
OIDTokenRequest *tokenExchangeRequest =
[_authState.lastAuthorizationResponse tokenExchangeRequest];
[self logMessage:#"Performing authorization code exchange with request [%#]",
tokenExchangeRequest];
[OIDAuthorizationService performTokenRequest:tokenExchangeRequest
callback:^(OIDTokenResponse *_Nullable tokenResponse,
NSError *_Nullable error) {
if (!tokenResponse) {
[self logMessage:#"Token exchange error: %#", [error localizedDescription]];
} else {
[self logMessage:#"Received token response with accessToken: %#", tokenResponse.accessToken];
}
[_authState updateWithTokenResponse:tokenResponse error:error];
GTMAppAuthFetcherAuthorization *gtmAuthorization =
[[GTMAppAuthFetcherAuthorization alloc] initWithAuthState:authState];
// Sets the authorizer on the GTLRYouTubeService object so API calls will be authenticated.
self.youTubeService.authorizer = gtmAuthorization;
// Serializes authorization to keychain in GTMAppAuth format.
[GTMAppAuthFetcherAuthorization saveAuthorization:gtmAuthorization
toKeychainForName:kGTMAppAuthKeychainItemName];
[self uploadVideoFile];
}];
} else {
[self logMessage:#"Authorization error: %#", [error localizedDescription]];
}
}];
}
This method cause this flow:
app send user to google login page in safari -> user log with his credentials -> after login, user is redirect back to my app -> the block success call the method UploadVideo.
This part of the flow seems to work correctly, i obtain a valid token as the log says. The second part is the video upload that consist in two main methods:
- (void)uploadVideoFile {
// Collect the metadata for the upload from the user interface.
// Status.
GTLRYouTube_VideoStatus *status = [GTLRYouTube_VideoStatus object];
status.privacyStatus = #"public";
// Snippet.
GTLRYouTube_VideoSnippet *snippet = [GTLRYouTube_VideoSnippet object];
snippet.title = #"title";
NSString *desc = #"description";
if (desc.length > 0) {
snippet.descriptionProperty = desc;
}
NSString *tagsStr = #"tags";
if (tagsStr.length > 0) {
snippet.tags = [tagsStr componentsSeparatedByString:#","];
}
GTLRYouTube_Video *video = [GTLRYouTube_Video object];
video.status = status;
video.snippet = snippet;
[self uploadVideoWithVideoObject:video
resumeUploadLocationURL:nil];
}
- (void)uploadVideoWithVideoObject:(GTLRYouTube_Video *)video
resumeUploadLocationURL:(NSURL *)locationURL {
NSURL *fileToUploadURL = [NSURL fileURLWithPath:self.VideoUrlCri.path];
NSError *fileError;
NSLog(#"step");
if (![fileToUploadURL checkPromisedItemIsReachableAndReturnError:&fileError]) {
NSLog(#"exit");
return;
}
// Get a file handle for the upload data.
NSString *filename = [fileToUploadURL lastPathComponent];
NSString *mimeType = [self MIMETypeForFilename:filename
defaultMIMEType:#"video/mp4"];
GTLRUploadParameters *uploadParameters =
[GTLRUploadParameters uploadParametersWithFileURL:fileToUploadURL
MIMEType:mimeType];
uploadParameters.uploadLocationURL = locationURL;
GTLRYouTubeQuery_VideosInsert *query =
[GTLRYouTubeQuery_VideosInsert queryWithObject:video
part:#"snippet,status"
uploadParameters:uploadParameters];
query.executionParameters.uploadProgressBlock = ^(GTLRServiceTicket *ticket,
unsigned long long numberOfBytesRead,
unsigned long long dataLength) {
NSLog(#"upload progress");
};
GTLRYouTubeService *service = self.youTubeService;
_uploadFileTicket = [service executeQuery:query
completionHandler:^(GTLRServiceTicket *callbackTicket,
GTLRYouTube_Video *uploadedVideo,
NSError *callbackError) {
if (callbackError == nil) {
NSLog(#"uploaded");
} else {
NSLog(#"error %#",callbackError);
}
}];
}
- (NSString *)MIMETypeForFilename:(NSString *)filename
defaultMIMEType:(NSString *)defaultType {
NSString *result = defaultType;
NSString *extension = [filename pathExtension];
CFStringRef uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension,
(__bridge CFStringRef)extension, NULL);
if (uti) {
CFStringRef cfMIMEType = UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType);
if (cfMIMEType) {
result = CFBridgingRelease(cfMIMEType);
}
CFRelease(uti);
}
return result;
}
I obtain a 403 error in NSLog(#"error %#",callbackError); and i can't see error details because the are something like :
data=<7b226572 726f7222 3a7b2265 72726f72 73223a5b 7b22646f 6d61696e 223a2267 6c6f6261 6c222c22 72656173 6f6e223a 22696e73 75666669 ... 61676522 3a22496e 73756666 69636965 6e742050 65726d69 7373696f 6e227d7d>}
In google api console i have created a Client Oauth for my application bundle and an API key, i use those values for my connection, it seems they works correctly because i obtain a valid token. Anyway, there someone who can help me or point me in the right direction about this error? Or there someone who knows a working example about a video upload for IOS and not for MAC ? There something weird in my code? I can't find any help in documentation or google

Unable to see update value in Quick Blox Admin Panel

I am using QuickBlox SDK from follwing refrence
https://quickblox.com/developers/SimpleSample-chat_users-ios
In Sample chat I am also making Group video chat . but When I Update particular tag With the help of below code. Than I am unable to see the updated value in my quickblox admin panel. If some one update the tag name than Please suggest me. I am using below code
QBUUser *qbUser = [QBUUser user];
qbUser.ID = 23429378;
NSString *roomName = #"ios group";
qbUser.tags = #[roomName].mutableCopy;
NSArray *arry = [[NSArray alloc]initWithObjects:qbUser, nil];
[QMUsersCache.instance insertOrUpdateUsers:users];
- (BFTask *)insertOrUpdateUsers:(NSArray *)users
{
__weak __typeof(self)weakSelf = self;
return [BFTask taskFromExecutor:[BFExecutor executorWithDispatchQueue:self.queue] withBlock:^id{
__typeof(self) strongSelf = weakSelf;
NSManagedObjectContext* context = [strongSelf backgroundContext];
NSMutableArray *toInsert = [NSMutableArray array];
NSMutableArray *toUpdate = [NSMutableArray array];
//To Insert / Update
for (QBUUser *user in users)
{
CDUser *cachedUser = [CDUser QM_findFirstWithPredicate:IS(#"id", #(user.ID)) inContext:context];
if (cachedUser) {
QBUUser *qbCachedUser = [cachedUser toQBUUser];
if (![user.updatedAt isEqualToDate:qbCachedUser.updatedAt]) {
[toUpdate addObject:user];
}
}
else {
[toInsert addObject:user];
}
}
if (toUpdate.count > 0) {
[strongSelf updateUsers:toUpdate inContext:context];
}
if (toInsert.count > 0) {
[strongSelf insertUsers:toInsert inContext:context];
}
if (toInsert.count + toUpdate.count > 0) {
[context QM_saveToPersistentStoreAndWait];
}
QMSLog(#"[%#] Users to insert %tu, update %tu", NSStringFromClass([weakSelf class]), toInsert.count, toUpdate.count);
return nil;
}];
}
Your code is just updating users in CoreData store.
You can update only the current user from the application:
+ (QBRequest *)updateCurrentUser:(QBUpdateUserParameters *)parameters
successBlock:(nullable void (^)(QBResponse *response, QBUUser * _Nullable user))successBlock
errorBlock:(nullable QBRequestErrorBlock)errorBlock;
If you want to update other users you should do it via Admin Panel.
Sample chat related to this question.
API Documentation related to this question.

How many data in bytes can I send at a time via bluetooth?

I'm using GKPeerPickerController and GKSession classes and I'm trying to send rather large amount of data (appr 20 mb, images). The problem is that when I send more then, say 10 megabytes the appropriate delegate method of the receiver (- (void) receiveData:(NSData *)data fromPeer:(NSString *)peer inSession: (GKSession *)session context:(void *)context;) simply does not getting called. Is there some size restrictions? There is no completion handlers or errors returned. The data is sent to nowhere...I have another question also - is it possible to notify the sender that the data is received? (So that I can send queued packages). Thanks in advance!
Added
This method forms a dictionary with objects which I want to send
- (void)sendQuiz:(id<BlitzModelQuizProtocol>)quiz {
if ([quiz.backgroundType intValue] == BackgroundTypeUser) {
NSMutableDictionary * background = [NSMutableDictionary new];
NSString * filePath = [[BUIFileManager sharedInstance] filePathWithFileName:quiz.backgroundPath];
NSData * imageData = [NSData dataWithContentsOfFile:filePath];
[background setObject:imageData forKey:kQuizBackgroundImage];
[background setObject:quiz.backgroundPath forKey:kQuizBackgroundName];
[self.objectsToSend setObject:background forKey:kQuizBackground];
}
for (id<BlitzModelQuestionProtocol>question in quiz.questions) {
// Improve this logic when answers become > 1
if ([question.smileyType intValue] == SmileyTypeCustom) {
NSMutableArray * customSmiles = [NSMutableArray new];
for (id<BlitzModelAnswerProtocol>answer in question.answers) {
NSLog(#"smiley is: %#", answer.smiley);
NSMutableDictionary * smiles = [NSMutableDictionary new];
NSString * filePath = [[BUIFileManager sharedInstance] filePathWithFileName:answer.smiley];
NSData * imageData = [NSData dataWithContentsOfFile:filePath];
[smiles setObject:answer.smiley forKey:kSmileName];
[smiles setObject:imageData forKey:kSmileImage];
[customSmiles addObject:smiles];
}
[self.objectsToSend setObject:customSmiles forKey:kCustomSmiles];
}
}
NSArray * statistics = [self statisticsForQuizId:quiz.objectId];
if ([statistics count] > 0) {
NSMutableArray * blitzStatistics = [NSMutableArray new];
for (id<BlitzModelStatisticProtocol>stat in statistics) {
BlitzStatistic * statistic = [[BlitzStatistic alloc] initWithObject:stat];
[blitzStatistics addObject:statistic];
}
[self.objectsToSend setObject:blitzStatistics forKey:kStatiscticObjects];
}
else {
BlitzQuiz * quizModelObject = [[BlitzQuiz alloc] initWithObject:quiz];
[self.objectsToSend setObject:quizModelObject forKey:kQuizObject];
}
NSData * data = [NSKeyedArchiver archivedDataWithRootObject:self.objectsToSend];
[self sendDataToPeers:data];
}
This is my sendData method:
- (void) sendDataToPeers:(NSData *) data {
NSString * title;
if (self.currentSession) {
NSError * error = nil;
if ([self.currentSession sendDataToAllPeers:data
withDataMode:GKSendDataReliable
error:&error]) {
NSLog(#"quiz sent");
}
else {
NSLog(#"error desc is: %#", [error localizedDescription]);
}
}
}
The method - (BOOL)sendDataToAllPeers:(NSData *)data withDataMode:(GKSendDataMode)mode error:(NSError **)error returns YES with no error (it's nil). What am I doing wrong?
Added
Sometimes the data is received successfully though sendData still returns NO without any error. Neither of delegate methods that handle error is getting called.

Cocos2D MenuLevel how to lock, unlock

I am using MenuLevel in my game for loading levels.. http://www.prioregroup.com/iphone/menulevel.aspx
At the moment, whether a level is locked or not, it's loading.. If it's locked, it should not be loading.. How can I do that? Thanks..
// create menu item
[menu createMenuItemLevel:1 position:ccp(x, size.height / 2) life:0 locked:NO];
- (void)menuLevel:(MenuLevel *)menuLevel buttonSelected:(id)source
{
CCMenuItem *item = (CCMenuItem*)source;
NSString *msg = [NSString stringWithFormat:#"You have pressed the button # %d", item.tag]; // retrieve level number..
NSLog(#"MenuLevel Sample %#", msg);
// What I want is something like.. if (item.locked == YES) do something
}
You can use the userData property. In your MenuLevel.m file add the following lines in
- (CCMenuItem*)createMenuItemLevel:(NSInteger)level
position:(CGPoint)position
life:(NSInteger)life
locked:(BOOL)locked
target:(id)target
selector:(SEL)selector
method.
if (locked)
{
item.userData = #"locked";
}
else
{
item.userData = #"notLocked";
}
And in your buttonSelected: method check that userData as given below:
NSString *lockString = (NSString *)item.userData;
if ([lockString isEqualToString:#"locked"])
{
// Locked level
}
else
{
// Unlocked
}

ios - GET method on an application

i have this application that has a username & password . however i need to make it log in on a particular site and add a user and check profiles..i was told that i must use GET to add a user or query and parse the returning data's in json.
What are the particular steps that i will do?
i have tried some ways but it really didn't help at all
i searched on google but it seems that the one's that i found is not the one that i need.
thanks in advance :)
PS:im new to programming so please be gentle on me.(dived right in to ios dev.)
i have created the app and it goes like this
edited:
i modified it a bit
- (IBAction)getDataPressed
{
if([myRequest_ isExecuting])
{
return;
}
if(myRequest_ != nil)
{
[myRequest_ release];
}
myRequest_ = [[ASIHTTPRequest alloc]initWithURL:[NSURL URLWithString:URL_PATH]];
myRequest_.delegate = self;
[myRequest_ startAsynchronous];
}
#pragma ASI Delegate methods
- (void)requestFinished:(ASIHTTPRequest *)request
{
NSLog(#"Request finished successfully");
NSLog(#"%#",[request responseString]);
NSDictionary *responseDictionary = [[request responseString]JSONValue];
NSDictionary *arrayElement = [responseDictionary objectForKey:#"user"];
NSString *ID = [arrayElement valueForKeyPath:#"id"];
NSLog(#"id: %d",ID);
NSString *usr = [arrayElement valueForKeyPath:#"usr"];
NSLog(#"usr: %#",usr);
NSString *gd = [arrayElement valueForKeyPath:#"gd"];
NSLog(#"gd: %#",gd);
NSString *age = [arrayElement valueForKeyPath:#"ag"];
NSLog(#"ag: %#",age);
NSString *st = [arrayElement valueForKeyPath:#"st"];
NSLog(#"st: %#",st);
NSString *lf = [arrayElement valueForKeyPath:#"lf"];
NSLog(#"lf: %#",lf);
NSString *da = [arrayElement valueForKeyPath:#"da"];
NSLog(#"da: %d",da);
for(NSString *value in [arrayElement allValues]){
NSLog(#"Found Value %#",value);
label.text = value;
[value release];
[super release];
}
}
- (void)requestFailed:(ASIHTTPRequest *)request
{
NSLog(#"Request failed");
}
-(void)dealloc {
[super dealloc];
}
#end
still the same im getting the values but when i press the get data at the app. it closes. i need help pls. thanks i want the values to be posted on the label
You will have to check documentation provided for login API by them. Most probably might be using either POST request or OAuth authentication mechanism. Please try to provide detailed information in order to get proper help. :)

Resources