Can't load the GKAchievementDescription image with loadImageWithCompletionHandler - ios

I am working on Game Center for iOS devices using the sandbox environment. I am trying to load the achievement images I set up in iTunes Connect.
I am using loadAchievementDescriptionWithConpletionHandler successfully.
The problem happens when I try to load the image using loadImageWithCompletionHandler.
[self.description loadImageWithCompletionHandler:^(UIImage *image, NSError *error) {
if (!error) {
self.achievementImage = image;
}
}];
The problem is both the UIImage and the error are nil.
It is due to the sandbox environment ? Am I missing something ?
Thanks

I can load the image successfully. It looks like my image format was wrong.
I have deleted the achievement and created a new one using a 512x512 72 dpi image.
Using loadAchievementDescriptionsWithCompletionHandler. I load all the achievementDescriptions from Game Center. Then, I use loadImageWithCompletionHandler to extract the image.
[GKAchievementDescription loadAchievementDescriptionsWithCompletionHandler:^(NSArray *descriptions, NSError *error) {
if (!error) {
for (GKAchievementDescription *achievementDescription in descriptions) {
[self.achievementDescriptionDictionary setObject:achievementDescription
forKey:achievementDescription.identifier];
[achievementDescription loadImageWithCompletionHandler:^(UIImage *image, NSError *error) {
if (!error) {
if (image) {
UIImage *achievementimage = image;
}
}
}];
}
}
}];

Related

iOS Share extension cannot load panorama image

When I am sending a panorama image (made with default panorama mode of my iPhone) to my iOS Share extension, hasItemConformingToTypeIdentifier tells me that there is indeed an image sent, however loadItemForTypeIdentifier does not return anything.I don't have any completeRequestReturningItems on the whole flow which could prevent the loadItemForTypeIdentifier to proceed until the end. This works however fine with a normal image.
How come panorama images give issues ?
for (NSExtensionItem *item in self.extensionContext.inputItems)
{
for (NSItemProvider *itemProvider in item.attachments)
{
if ([itemProvider hasItemConformingToTypeIdentifier:(NSString *)kUTTypeImage])
{
NSLog(#"Found item:%#",item); --> Is displayed
[itemProvider loadItemForTypeIdentifier:(NSString *)kUTTypeImage options:nil completionHandler:^(UIImage *image, NSError *error)
{
NSLog(#"Item delivered"); --> Is never displayed for panorama pictures
if(image) {
selectedImage=image;
mediaType=1;
NSLog(#"Image found !!");
imageFound = YES;
}
}];
break;
}
}
}

Saving image in iOS photo album(my folder) and have the image url stored

I want to save an image (which is downloaded from server) in iOS device photo album and store that image photo album url in local database. My question is, How do i get that photo album image url after saving the image?
I am able to save the image in photo album using the following ALAsset code: But, I need this url image also to be stored in my local db. So next time, i won't download the same image from server and i can load directly from device photo album.
[self.maAssetsLibrary saveImage:image
toAlbum:#"My-Album"
completion:completion
failure:nil];
Please suggest.
UPDATE:
I tried this, but NOT getting me the photo album image URL after saving the image.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// The completion block to be executed after image taking action process done
void (^completion)(NSURL *, NSError *) = ^(NSURL *assetURL, NSError *error) {
};
[self.maAssetsLibrary saveImage:image toAlbum:#"My-Album" completion:^(NSURL *assetURL, NSError *error){
if (error) {
NSLog(#"error");
} else {
NSLog(#"url %#", assetURL);
}
} failure:^(NSError *error) {
}];
});
Due to sandboxing you can't get such a url. As #Lord Zsolt proposes in the comment, you can overcome this by saving images in your application's folder. In this case you might e.g. give them a name that serves as key to identify each image.
EDIT
As #MidhunMP commented, I was wrong on that! There is a way (and I'm happy to know that now) and it comes from this Stack Overflow answer, provided by #CRDave in the comment above.
The main point is to use ALAssetsLibrary's writeImageToSavedPhotosAlbum:orientation:completionBlock: method.
It's always nice to learn.

How to download an image using QuickBox API?

I'm trying to download an image file using Quickblox API. I can upload a file but when I try to download, NSData image doesn't show an image.
// Upload a user avatar, previously log in Quickblox API
NSData *avatar = UIImagePNGRepresentation([UIImage imageNamed:#"userWhite"]);
[QBRequest TUploadFile:avatar fileName:#"avatar.png" contentType:#"image/png" isPublic:YES successBlock:^(QBResponse *response, QBCBlob *blob) {
// Success
} statusBlock:^(QBRequest *request, QBRequestStatus *status) {
} errorBlock:^(QBResponse *response) {
}];
Image Upload: Image
Download avatar:
NSString* userProfilePictureID = [NSString stringWithFormat:#"%ld",(long)[[LocalStorageService shared] currentUser].blobID]; // user - an instance of QBUUser class
// download user profile picture
[QBRequest downloadFileWithUID:#"318547" successBlock:^(QBResponse *response, NSData *fileData) { UIImage* image = [UIImage imageWithData:fileData];
} statusBlock:^(QBRequest *request, QBRequestStatus *status) {
} errorBlock:^(QBResponse *response) {
}];
UIImage doesn't show any image. What can I do? NSData isn't corrupted.
Your download code looks right. You basically should call QBRequest method and pass blob.UID to it.
But in my case blob.UID is something like this 9357c3d66b944880a82cdbeb836f143c00. However there are steps I took to accomplish your task:
1) Sign up or login user
Either by calling +[QBRequest signUp:successBlock:errorBlock:] or +[QBRequest logInWithUserLogin:password:successBlock:errorBlock].
2) Enumerate through all available blobs for current user
[QBRequest blobsWithSuccessBlock:^(QBResponse* response,
QBGeneralResponsePage* page,
NSArray* blobs) {
[self findAndShowAvatarFromBlobs:blobs];
} errorBlock:^(QBResponse* response) { <...> }];
3) Find desired blob and download it
- (void)findAndShowAvatarFromBlobs:(NSArray*)blobs {
for (QBCBlob* blob in blobs) {
if ([blob.name hasPrefix:#"avatar"]) {
[QBRequest downloadFileWithUID:blob.UID
successBlock:^(QBResponse* response, NSData* fileData) {
UIImage* image = [UIImage imageWithData:fileData];
self.imageView.image = image;
}
statusBlock:^(QBRequest* request, QBRequestStatus* status) { <...> }
errorBlock:^(QBResponse* response) { <...> }];
}
}
}
Probably you have a problem with getting valid blob UID (I suspect that you are using blob ID which is not the same as UID). Is it possible for you to use the same kind of logic?
Full project you can find here: https://dl.dropboxusercontent.com/u/930742/so/QuickBloxSample.zip
It creates necessary user, uploads and then downloads image with showing it in UIImageView demonstrating all described steps. (Don't forget to set your service and application keys in AppDelegate)
P.S. In admin panel you can find blob UID by clicking on its ID in Content table

PFImageView -loadInBackground fails with error Code=150

So, I am trying to load an image that exists on my database, into a PFImageView
MyAccount.h
#property (weak, nonatomic) IBOutlet PFImageView *profilePic;
MyAccount.m
-(void)viewDidLoad
{
[super viewDidLoad];
PFUser *cUser = [PFUser currentUser];
// Get the user's profile pic
if(cUser[PF_USER_PIC]) {
NSLog(#"cUser[PF_USER_PIC] exists, description: %#",
[cUser[PF_USER_PIC] description]);
self.profilePic.file = cUser[PF_USER_PIC];
[self.profilePic loadInBackground:
^(UIImage *image, NSError *error) {
if (!error)
NSLog(#"profilePic loadInBackground completed");
else {
NSLog(#"profilePic loadInBackground failed with error: %#", error);
}
}];
}
}
But unfortunately this is never successful
2014-09-04 17:53:03.668 Rally[10281:60b]
cUser[PF_USER_PIC] exists, description: <PFFile: 0x17b070e80>
2014-09-04 17:53:03.972 Rally[10281:2ca3f]
profilePic loadInBackground failed with error:
Error Domain=Parse Code=150 "The operation couldn’t be completed. (Parse error 150.)"
I can't seem to find a solution via googling (not many results). Can anybody shed some light on what might be happening here?
Note that I can get saveInBackground working a charm. It's just the inbound direction I'm struggling with!
EDIT: Further information
I have tried using a UIImageView instead of a PFImageView, and linking that up instead. Here is the code:
PFFile *imageData = (PFFile *)cUser[PF_USER_PIC];
[imageData getDataInBackgroundWithBlock:
^(NSData *data, NSError *error) {
if (error) {
NSLog(#"getDataInBackground error: %#", [error localizedDescription]);
}
else {
NSLog(#"getDataInBackground SUCCESS");
self.profilePic.image = [UIImage imageWithData:data];
}
}];
This appears to work well:
2014-09-09 12:30:31.822 Rally[2266:60b]
cUser[PF_USER_PIC] exists, description: <PFFile: 0xaaa2080>
2014-09-09 12:30:31.835 Rally[2266:60b]
getDataInBackground SUCCESS
Yet, still not image appears!
Last but not least, if I replace [UIImage imageWithData:data] with [UIImage imageNamed:#"some_local_image"], this works perfectly. So the UIImageView is definitely hooked up.

iOS - Retrieve Picture from Parse currentUser

I'm using Parse.com as a backend for my iOS app.
I have a class called "User".
In this class I have a flied called "picture" with the users profile picture.
At the moment im kinda stuck on how i can fetch this picture for my currentUser and show it within an UIView (not UIImage) within my storyboard viewcontroller.
Maybe you guys have some sample code for that?
Thanks in Advance!
Amit, sorry your Code didnt work for me, my app crashed.
Here is my solution:
PFUser *cUser = [PFUser currentUser];
PFFile *pictureFile = [cUser objectForKey:#"picture"];
[pictureFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if (!error){
[_currentUserImage setImage:[UIImage imageWithData:data]];
}
else {
NSLog(#"no data!");
[_currentUserImage setImage:[UIImage imageNamed:#"profile"]]; //Set Custom Image if there is no user picture.
}
}];
}

Resources