Hi, guys I am almost done building this app I am making but I have this problem, I looked online on how to get a random keys and values from a NSDictionary it works fine also I have NSUserNotification to get the values from the NSDictionary and give the user a text/quotation. Here is my code:
But when the notification comes up more that one text/quotation comes up at the same time and overlap each other. Can anyone help?
Code:
-(void)friendshipTimer:(NSTimer *)friendshipTimer {
NSLog(@"NSUserNotificationCenter fired");
// refer to this for more help :http://www.renssies.nl/2012/02/mountain-lion-the-new-notifications-center/
NSBundle* bundle = [NSBundle mainBundle];
NSString* plistPath = [bundle pathForResource:@"friendshipKeys" ofType:@"plist"];
NSDictionary* plisttext = [NSDictionary dictionaryWithContentsOfFile:plistPath];
//Now to generate and display random sentences, you would need to keep a track of all the keys:
NSArray* keys = [plisttext allValues];
//Then select a random key using the index:
int randomIndex = arc4random() % (keys.count);
NSString* key = [keys objectAtIndex:randomIndex];
//Initalize new notification
NSUserNotification *notification = [[NSUserNotification alloc] init];
//Set the title of the notification
[notification setTitle:@"My Title"];
//Set the text of the notification
[notification setInformativeText:[NSString stringWithFormat:@"%@",key]];
//Set the sound, this can be either nil for no sound, NSUserNotificationDefaultSoundName for the default sound (tri-tone) and a string of a .caf file that is in the bundle (filname and extension)
[notification setSoundName:NSUserNotificationDefaultSoundName];
//Get the default notification center
NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter];
//Scheldule our NSUserNotification
[center scheduleNotification:notification];
}