Local notification plays only default sound after app update

Originator:Josh.Lieberman92
Number:rdar://30758362 Date Originated:28-Feb-2017
Status:Closed Resolved:
Product:iOS + SDK Product Version:iOS 10
Classification:Other Bug Reproducible:Always
 
Area:
Notifications

Summary:
The first load of an app with local notification custom sounds works correctly. When the app is updated (by Xcode, TestFlight or App Store) the app plays only the default sound. Behavior is the same with either new UNUserNotifications or deprecated UILocalNotifications. Behavior only occurs on iOS 10. The custom sound is a 2 second caf file in the application bundle (and it plays correctly multiple times until the app is updated). Notification permissions including Sounds are properly granted. Deleting the app and reloading causes the custom sound to play correctly again.

Steps to Reproduce:
1. Install original app
2. Update app via Xcode, TestFlight, or App Store
3. Send notification

Expected Results:
Custom notification sound is played

Actual Results:
Default notification sound is played

Version:
iOS 10

Notes:


Configuration:
All iOS devices

Attachments:
'AppDelegate.m' was successfully uploaded.

@interface AppDelegate ()  
@end  
  
@implementation AppDelegate  
  
BOOL soundsAllowed;  
  
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  
    NSLog(@"application didFinishLaunchingWithOptions");  
    [self requestAuthorizationForNotifications];     
    return YES;  
}  
  
- (void)applicationWillResignActive:(UIApplication *)application {  
    NSLog(@"applicationWillResignActive");  
}  
  
- (void)applicationDidEnterBackground:(UIApplication *)application {  
    NSLog(@"applicationDidEnterBackground");  
    [self scheduleLocalNotification];  
}  
  
- (void)applicationWillEnterForeground:(UIApplication *)application {  
    NSLog(@"applicationWillEnterForeground");  
    // check if we are still authorized  
    [self requestAuthorizationForNotifications];  
}  
  
- (void)applicationDidBecomeActive:(UIApplication *)application {  
    NSLog(@"applicationDidBecomeActive");  
}  
  
- (void)applicationWillTerminate:(UIApplication *)application {  
    NSLog(@"applicationWillTerminate");  
}  
  
- (void)requestAuthorizationForNotifications {  
    NSLog(@"requestAuthorizationForNotifications");  
    soundsAllowed = NO;  
    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];  
    [center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert + UNAuthorizationOptionSound | UNAuthorizationOptionAlert)  
                          completionHandler:^(BOOL granted, NSError * _Nullable error) {  
                              if (error) {  
                                  NSLog(@"request authorization error: %@", error);  
                              } else {  
                                  NSLog(@"request authorization no error");  
                                  [self checkSoundsAllowed];  
                              }  
                          }];}  
  
// examine notification settings to determine if sounds are allowed, save result  
- (void)checkSoundsAllowed {  
    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];  
    [center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {  
        soundsAllowed = (settings.soundSetting == UNNotificationSettingEnabled);  
        NSLog(@"soundsAllowed: %@", (soundsAllowed ? @"true" : @"false"));  
        if (soundsAllowed) {  
            // clear any existing notifications  
            [center removeAllPendingNotificationRequests];  
        }  
    }];  
}  
  
- (void)scheduleLocalNotification {  
    if (!soundsAllowed) {  
        NSLog(@"scheduleLocalNotification soundsAllowed: false. return without scheduling");  
        return;  
    }  
    
    // Set up the request content  
    UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];  
    content.title = @"Title";  
    content.body = @"Body";  
    content.sound = [UNNotificationSound soundNamed:@"Test.caf"];  
    
    // Deliver the notification in five seconds.  
    UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger  
                                                  triggerWithTimeInterval:5.f repeats:NO];  
    UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:@"FiveSecond"  
                                                                          content:content trigger:trigger];  
    // Schedule the notification.  
    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];  
    [center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {  
        if (!error) {  
            NSLog(@"addNotificationRequest succeeded! content.sound: %@ default sound: %@", content.sound, [UNNotificationSound defaultSound]);  
        }  
    }];  
}  
  
@end

Comments

Apple Developer Relations01-Mar-2017 12:06 PM

Engineering has the following feedback for you:

This was fixed in iOS 10.2.

Please verify this issue with the iOS 10.2.1 GM:

iOS 10.2.1 GM (14D27) https://developer.apple.com/download/ Posted Date: Jan 23rd, 2017

We are now closing this bug report.

If you have questions or comments about the resolution, please update your bug report with that information so we can respond.

By Josh.Lieberman92 at March 29, 2017, 9:26 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!