2016-10-24 7 views
0

私はローカル通知を発しています。 UILocalNotificationクラスは、私がUNNotification:LocalNotificationのカスタムサウンドがiOS10で再生されていません

UserNotifications.frameworkを使用していたiOS10で非推奨 あるので、私は、通知用のカスタムサウンドを設定しようとすると、デフォルトの音はすべての時間を再生しています。ここ

は私のコードです:

- (IBAction)fireLocalNotification:(id)sender { 

    UNMutableNotificationContent* content = [[UNMutableNotificationContent alloc] init]; 
    content.title = [NSString localizedUserNotificationStringForKey:@"Hello!" arguments:nil]; 
    content.body = [NSString localizedUserNotificationStringForKey:@"Hello_message_body" 
                 arguments:nil]; 
    content.sound = [UNNotificationSound soundNamed:@"sound.mp3"]; 

    // Deliver the notification in five seconds. 
    UNTimeIntervalNotificationTrigger* trigger = [UNTimeIntervalNotificationTrigger 
                triggerWithTimeInterval:5 repeats:NO]; 

    UNNotificationRequest* request = [UNNotificationRequest requestWithIdentifier:@"FiveSecond" 
                      content:content trigger:trigger]; 

    // Schedule the notification. 
    UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter]; 
    [center addNotificationRequest:request withCompletionHandler:^(NSError *error){ 

     if(!error){ 

      NSLog(@"Completion handler for notification"); 
     } 

    }]; 
} 

私の音微sound.mp3がプロジェクトバンドル自体に存在しています。

詳細: https://developer.apple.com/reference/usernotifications/unusernotificationcenter?language=objc

+0

.MP3ファイルは、あなたのプロジェクトに追加されていることである - ターゲット - コピーバンドルリソース? – Wolverine

+0

はい、それは私のバンドルに存在し、ターゲットに追加されました - バンドルリソースのコピー –

+0

デバイスからアプリを削除して、デバイス内のアプリを再実行して再実行してみてください。 – Wolverine

答えて

3

、デバイスからアプリを削除してみてください清潔で、デバイスにアプリを再度実行してください。

時事通信のリソースが適切に更新されていないと、私は思っています。あなたの問題です。

+0

Yuppp!ありがとう... –

0

ロングオーディオファイルは

をサポートしていませんが、より長い30秒後、あなたのファイルか? 「はい」の場合は動作しません。 30秒未満のファイルのみが利用可能です。ファイルの長さが30秒を超えると、デフォルトのサウンドに置き換えられます。

UNNotificationSound documentation

+2

その情報を入手したドキュメントへのリンクを提供することは、常に役立ちます。 https://developer.apple.com/documentation/usernotifications/unnotificationsound –

+1

ありがとうございました@KaiEngelhardt、私はそれを付けました。 –

+0

問題は解決しました。それはリソースの更新によるものです...答えに感謝.. –

関連する問題