Xcode - *.png per NSString ( api ) abrufen und UIImage erzeugen

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Xcode - *.png per NSString ( api ) abrufen und UIImage erzeugen

    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 :

    Quellcode

    1. NSDate *myDate = (NSDate *)[[NSUserDefaults standardUserDefaults] objectForKey:@"LastUpdate"];
    2. NSString *theUrl = [NSString stringWithFormat:@"http://xxx:xxxt@api.musterserver.info/api.php?function=checkForClubUpdates&params=lastupdate=%@;encoding=utf8", myDate];
    3. NSURL *url = [NSURL URLWithString:[theUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    4. JImage *photoImage=[[JImage alloc] init];
    5. [photoImage setContentMode:UIViewContentModeScaleAspectFill];
    6. [photoImage setFrame:CGRectMake(65, 5, 30, 30)];
    7. [photoImage initWithImageAtURL:url];
    8. [updateimageDisplay addSubview:photoImage];
    9. NSLog(@"Checking Update image ---->: %@",theUrl);


    und die Klassen dazu:

    Quellcode

    1. #import <Foundation/Foundation.h>
    2. #import <UIKit/UIKit.h>
    3. @interface JImage : UIImageView {
    4. NSURLConnection *connection;
    5. NSMutableData* data;
    6. UIActivityIndicatorView *ai;
    7. }
    8. -(void)initWithImageAtURL:(NSURL*)url;
    9. @property (nonatomic, retain) NSURLConnection *connection;
    10. @property (nonatomic, retain) NSMutableData* data;
    11. @property (nonatomic, retain) UIActivityIndicatorView *ai;
    12. @end
    Alles anzeigen

    Quellcode

    1. #import "JImage.h"
    2. @implementation JImage
    3. @synthesize ai,connection, data;
    4. -(void)initWithImageAtURL:(NSURL*)url
    5. {
    6. [self setContentMode:UIViewContentModeScaleAspectFit];
    7. if (!ai){
    8. [self setAi:[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]];
    9. [ai startAnimating];
    10. [ai setFrame:CGRectMake(0, 0, 20, 20)];
    11. [self addSubview:ai];
    12. }
    13. NSURLRequest* request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:15];
    14. connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
    15. }
    16. - (void)connection:(NSURLConnection *)theConnection didReceiveData:(NSData *)incrementalData {
    17. if (data==nil) data = [[NSMutableData alloc] initWithCapacity:2048];
    18. [data appendData:incrementalData];
    19. }
    20. - (void)connectionDidFinishLoading:(NSURLConnection*)theConnection
    21. {
    22. [self setImage:[UIImage imageWithData: data]];
    23. [ai removeFromSuperview];
    24. }
    25. - (void)connection:(NSURLConnection *)theConnection
    26. didFailWithError:(NSError *)error {
    27. // Handle error
    28. [ai removeFromSuperview];
    29. }
    30. -(void)dealloc{
    31. [data release];
    32. [connection release];
    33. [ai release];
    34. [super dealloc];
    35. }
    36. @end
    Alles anzeigen
    Vielleicht hat ja wer eine gute lösung oder könnete mir bei meinem Problem helfen.

    Danke
  • Was funktioniert denn nicht mehr? Meiner Meinung nach macht es mehr Sinn, einen Fehler zu beheben, statt blind eine neue Lösung zu suchen. Eventuell ist Dein Problem ja z. B. nur ein blockierendes ATS...

    Vielleicht überdenkst Du Dein Problem noch einmal und formulierst es dann etwas sorgfältiger...

    Mattes
    Diese Seite bleibt aus technischen Gründen unbedruckt.