• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSSharingService with Animated GIFs?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSSharingService with Animated GIFs?


  • Subject: Re: NSSharingService with Animated GIFs?
  • From: Ken Thomases <email@hidden>
  • Date: Sat, 17 May 2014 01:03:20 -0500

On May 17, 2014, at 12:41 AM, Charles Carver wrote:

> Thanks for the response. NSImage never ended up working, but your suggestion of attaching the local URL worked:

I'm glad you got something working, but…

> NSString *fileUrl = @"http://i.imgur.com/V8w9fKt.gif";;

Probably best to not name things which aren't NSURLs as "url".  At least, call it a "URL string", perhaps "fileURLString" or, since it's the source of an image, "imageURLString".

> NSString *fileName = [fileUrl lastPathComponent];

It is not legal to use -[NSString lastPathComponent] on a string which is not a file path.  The docs even call this out:

"Note that this method only works with file paths (not, for example, string representations of URLs)."

> NSURL *saveUrl = [NSURL URLWithString:[NSString stringWithFormat:@"file://%@", NSTemporaryDirectory()]];

It's not correct to try to construct a file URL by prepending "file://" to a path string.  Paths can have characters which are not valid in URLs.  The following is correct and simpler as well:

NSURL * saveUrl = [NSURL fileURLWithPath:NSTemporaryDirectory()];

> saveUrl = [saveUrl URLByAppendingPathComponent:fileName];
> // Write image to temporary directory
> NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:fileUrl]];

You should consider what happens if the server is slow to respond.  The above call will block until the image download is complete.  Better to use the asynchronous URL loading mechanisms in the frameworks (e.g. NSURLSession).

Regards,
Ken


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: NSSharingService with Animated GIFs?
      • From: Charles Carver <email@hidden>
References: 
 >Re: NSSharingService with Animated GIFs? (From: Charles Carver <email@hidden>)
 >Re: NSSharingService with Animated GIFs? (From: Ken Thomases <email@hidden>)
 >Re: NSSharingService with Animated GIFs? (From: Charles Carver <email@hidden>)

  • Prev by Date: Re: NSSharingService with Animated GIFs?
  • Next by Date: Re: NSSharingService with Animated GIFs?
  • Previous by thread: Re: NSSharingService with Animated GIFs?
  • Next by thread: Re: NSSharingService with Animated GIFs?
  • Index(es):
    • Date
    • Thread