问题描述:

I'm Using LocalNotification for ios 8,Badge icon and Sound is not working fine for me even in the real device.Here is my code

in AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

// Override point for customization after application launch.

if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)])

{

[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];

}

[self.window makeKeyAndVisible];

return YES;

}

in ViewController.m

UILocalNotification *localNotification = [[UILocalNotification alloc] init];

localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];

localNotification.alertBody = @"Time to get up!";

localNotification.soundName = UILocalNotificationDefaultSoundName;

localNotification.timeZone=[NSTimeZone defaultTimeZone];

[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

localNotification.applicationIconBadgeNumber=1;

网友答案:

you have to set badge before schedule notification

localNotification.applicationIconBadgeNumber=1;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

for sound your code is correct. check your device sound. from settings > sounds.

相关阅读:
Top