2016-06-15 5 views
0

[Objective Cの中に]サウンドを再生しないとバッジアラートを表示しませんプッシュ通知:iOSのは、私がここで提供デモ命令を使用していた

:ここ https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIAlertController_class/

はメインのコードです

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

    UIUserNotificationType types = (UIUserNotificationType) (UIUserNotificationTypeBadge |                
UIUserNotificationTypeSound | UIUserNotificationTypeAlert); 


    UIUserNotificationSettings *mySettings = 
    [UIUserNotificationSettings settingsForTypes:types categories:nil]; 

    [[UIApplication sharedApplication] registerUserNotificationSettings:mySettings]; 

    return YES; 
} 

-(void)MessageBox:(NSString *)title message:(NSString *)messageText 
{ 
    // OLD way of sending push notifications: 

    // UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:messageText delegate:self 
    //          cancelButtonTitle:@"OK" otherButtonTitles: nil]; 
    // [alert show]; 


    UIAlertController* alert= [UIAlertController 
            alertControllerWithTitle:title 
            message:messageText 
           preferredStyle:UIAlertControllerStyleAlert]; 


    UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault 
                  handler:^(UIAlertAction * action) {}]; 

    [alert addAction:defaultAction]; 
    [self.window.rootViewController presentViewController:alert animated:YES completion:nil]; 

} 

通知が表示されますが、サウンドとバッジの更新はありません。 提案がありますか?

+0

実際にあなたのサーバーのAPNSにリモート通知を送信しているのですか、アプリでローカル通知を使用していますか?あなたがしているのは、バッジとサウンドがないという意味の警告ダイアログを表示しているようです。 –

+0

両方のフィードバックありがとう。私は完全にはっきりしていなかった。コードでバッジとサウンドを設定していました。その後、サードパーティのペイロードを送信します。私のペイロードメッセージは不完全でした。 –

答えて

1

JSONペイロードにバッジとサウンドのパラメータを含めましたか?

{"aps":{"alert":"Example notification title","badge":1,"sound":"default"}} 

私は慣れるためにApple Push Notification Payload Documentsにまで読みました。

+0

ああ。すべてが今働きます。私の元のメッセージは... {"aps":{"alert": "通知の例題"}}のようなものでした。私はサウンドとバッジがペイロードを通じて行われたとは思わなかった。私は彼らがApp Delegateでセットアップされなければならないと思っていました。そして、電話は推測するでしょう。うわー! –

+0

@ js_55 JSONペイロードでAPNドキュメントを読むことをお勧めします。最初は非常に扱いにくい可能性があるため、すべてを理解してください。ここにリンクがあります:https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/TheNotificationPayload.html#//apple_ref/doc/uid/TP40008194-CH107-SW1 –

関連する問題