I want to give my user the option to "share" my apps detailed view page.
Once the user clicks "tweet this" I want the initialText to include a date string ('release_date') that's being parsed with JSON. I'm having trouble displaying the date string in a readable format.
This is how I'm formatting the date (in a NSObject)
- (NSString *) formattedDate {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"];
NSDate *readableDate = [dateFormatter dateFromString:self.release_date];
[dateFormatter setDateFormat:@"MMMM dd"];
return [dateFormatter stringFromDate:readableDate];
}
My release_date is a NSString (this is how the JSON looks)
release_date: "2013-11-16T00:00:00.000Z"
This is how I'm displaying the formattedDate in my detailedViewController
- (void)viewDidLoad
{
[super viewDidLoad];
if([_singleRelease objectForKey:@"release_date"] != NULL)
{
NSString *readableDate = [_singleRelease objectForKey:@"release_date"];
UpcomingRelease *singleRelease = [[UpcomingRelease alloc] init];
singleRelease.release_date = readableDate;
self.release_date.text = [NSString stringWithFormat:@"%@", singleRelease.formattedDate];
}
}
My SLComposeViewController
- (IBAction)shareOnTwitter:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet = [SLComposeViewController
composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:[NSString stringWithFormat:@"%@ is releasing on %@, via @soleresource", [_singleRelease objectForKey:@"release_name"], [_singleRelease objectForKey:@"release_date"]]];
[self presentViewController:tweetSheet animated:YES completion:nil];
}
}
Thanks