Hallo Leute, bitte um eure mithilfe.
im neuen xcode funktioniert
mein api NSURL code nicht mehr so wie er soll , ich würde das abrufen
meines Update Icons gerne ganz einfach und simpel erstellen.
Beim
Abrufen meiner api wird ein Datums String mitgesendet und wenn
erfolgreich ein kleines *.png Bildchen als UIImage angezeigt.
Als
Frameworgs hätte ich bereits im Projekt : SDWebImage und AFNetworking,
vielleich weis jemand wie ich es am schönsten realisieren könnte. Das
UIImage sollte natürlich nicht gecacht werden.
mein code derzeit :
und die Klassen dazu:
Alles anzeigen
Alles anzeigen
Vielleicht hat ja wer eine gute lösung oder könnete mir bei meinem Problem helfen.
Danke
im neuen xcode funktioniert
mein api NSURL code nicht mehr so wie er soll , ich würde das abrufen
meines Update Icons gerne ganz einfach und simpel erstellen.
Beim
Abrufen meiner api wird ein Datums String mitgesendet und wenn
erfolgreich ein kleines *.png Bildchen als UIImage angezeigt.
Als
Frameworgs hätte ich bereits im Projekt : SDWebImage und AFNetworking,
vielleich weis jemand wie ich es am schönsten realisieren könnte. Das
UIImage sollte natürlich nicht gecacht werden.
mein code derzeit :
Quellcode
- NSDate *myDate = (NSDate *)[[NSUserDefaults standardUserDefaults] objectForKey:@"LastUpdate"];
- NSString *theUrl = [NSString stringWithFormat:@"http://xxx:xxxt@api.musterserver.info/api.php?function=checkForClubUpdates¶ms=lastupdate=%@;encoding=utf8", myDate];
- NSURL *url = [NSURL URLWithString:[theUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
- JImage *photoImage=[[JImage alloc] init];
- [photoImage setContentMode:UIViewContentModeScaleAspectFill];
- [photoImage setFrame:CGRectMake(65, 5, 30, 30)];
- [photoImage initWithImageAtURL:url];
- [updateimageDisplay addSubview:photoImage];
- NSLog(@"Checking Update image ---->: %@",theUrl);
und die Klassen dazu:
Quellcode
- #import <Foundation/Foundation.h>
- #import <UIKit/UIKit.h>
- @interface JImage : UIImageView {
- NSURLConnection *connection;
- NSMutableData* data;
- UIActivityIndicatorView *ai;
- }
- -(void)initWithImageAtURL:(NSURL*)url;
- @property (nonatomic, retain) NSURLConnection *connection;
- @property (nonatomic, retain) NSMutableData* data;
- @property (nonatomic, retain) UIActivityIndicatorView *ai;
- @end
Quellcode
- #import "JImage.h"
- @implementation JImage
- @synthesize ai,connection, data;
- -(void)initWithImageAtURL:(NSURL*)url
- {
- [self setContentMode:UIViewContentModeScaleAspectFit];
- if (!ai){
- [self setAi:[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]];
- [ai startAnimating];
- [ai setFrame:CGRectMake(0, 0, 20, 20)];
- [self addSubview:ai];
- }
- NSURLRequest* request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:15];
- connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
- }
- - (void)connection:(NSURLConnection *)theConnection didReceiveData:(NSData *)incrementalData {
- if (data==nil) data = [[NSMutableData alloc] initWithCapacity:2048];
- [data appendData:incrementalData];
- }
- - (void)connectionDidFinishLoading:(NSURLConnection*)theConnection
- {
- [self setImage:[UIImage imageWithData: data]];
- [ai removeFromSuperview];
- }
- - (void)connection:(NSURLConnection *)theConnection
- didFailWithError:(NSError *)error {
- // Handle error
- [ai removeFromSuperview];
- }
- -(void)dealloc{
- [data release];
- [connection release];
- [ai release];
- [super dealloc];
- }
- @end
Danke