Post

Replies

Boosts

Views

Activity

NSDictionary returns wrong values for NSDate in other Time Zones
I'm storing dates in an NSDictionary and even though it creates a very weird value when stored, it returns the correct time in my time zone. However, if I change my time zone and read the value, I don't get values offset by the hour - I get weird values: Original time in my date object in NY: 9:10:20 am Value stored in Dict: Dict {Time = "0001-01-01 14:06:22 +0000";} Value returned from objectForKey: New York 9:10:20 am Chicago 8:15:46 am Denver 7:06:26 am California 6:13:24 am I'll post my code here but I'm at a loss to figure out how to fix this. NSLog(@"Original Date %@",date); NSDictionary *myDict = [[NSDictionary alloc] initWithObjectsAndKeys:date,@"Time", nil]; NSLog(@"MyDict %@", myDict); NSDate *tempDate = [myDict objectForKey:@"Time"]; NSLog(@"tempDate %@",tempDate); Even if I format it, it is wrong: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4]; [dateFormatter setDateStyle:NSDateFormatterNoStyle]; [dateFormatter setTimeStyle:NSDateFormatterNoStyle]; [dateFormatter setDateFormat:@"h:mm:ss a"]; return [dateFormatter stringFromDate:date]; The good news is that it seems to convert to/from NSDictionary in whatever time zone it was created in, but this is a big issue for anyone that travels with our app. Thoughts about what causes this and what can fix it? If the app wasn't already released and in use, I'd simply change my storage format. I need to have this work with existing data.
2
0
502
Mar ’23
How to addObserver for currentPlaybackTime for the system music player?
I'm using the systemMusicPlayer to play music and want to update the playback time using addObserver forKeyPath. [self setMusicPlayer: [MPMusicPlayerController systemMusicPlayer]]; I've tried these two methods: [self addObserver:self forKeyPath:@"musicPlayer.currentPlaybackTime" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial context:&musicPlayer]; [self.musicPlayer addObserver:self forKeyPath:@"currentPlaybackTime" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial context:&musicPlayer]; I do get the initial values for currentPlaybackTime in: -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context but I never get any calls when the player is playing the song (the whole point). If I set the currentPlaybackTime to a specific value (locating manually using a slider), I get calls with the values I set (useless since I know what I am setting them to). How are we supposed to track the playback time without just polling it constantly?
1
0
583
May ’24
How to detect the end of playback with the system music player?
Since iOS 12 it has become difficult to detect the end of playback using the system music player. In earlier iOS versions, the now playing item would be set nil and you would receive a notification that the player stopped. In iOS 12 and later, nowPlayingItem still contains the current song and the only notification you get is MPMusicPlayerControllerPlaybackStateDidChangeNotification with the playbackState set to MPMusicPlaybackStatePaused. Pressing pause in my car (or any remote access) generates the same conditions making it difficult to correctly detect the difference. It would be nice if they added a notification that playback was done (similar to the other players). Any suggestions?
0
0
526
May ’24
UIImageView is caching all of my images causing memory issues
I'm using a UIImageView to display album artwork when playing music. Every time new artwork is loaded, the memory usage increases. I'm using ARC and tried a autoreleasepool around the code. If I put the app in the background, the cache clears and it starts using up memory again. Here's my code: - (void) showArtwork { @autoreleasepool { MPMediaItem *currentItem = [self.musicPlayer nowPlayingItem]; if (currentItem) { MPMediaItemArtwork *artwork = [currentItem valueForProperty: MPMediaItemPropertyArtwork]; if (artwork) { UIImage *artworkImage = [artwork imageWithSize: CGSizeMake (339, 339)]; if (artworkImage) { [self.appCoverArt setImage: artworkImage]; } } } } } musicPlayer is the systemMusicPlayer appCoverArt is my UIIMageView 1. Is there a way to release an image from UIImageView before assigning a new image? 2. Is there a way to clear the pool other than putting the app in the background (which does clear the memory)?
6
2
759
Jun ’24
Placing text over images
What is the best way to display text over images - I'd like the image to fade to white underneath the text so that the text is easier to read since I have no control over the contents of the images. I thought about having a second label behind the actual label with the same text in a slightly larger font and white color. but I'd rather have it be a gradual fading of the image just under the text rather than what looks like 3D text. Any suggestions?
3
0
615
Jun ’24