&tag(iOSSDK/Local Notification);
*目次 [#e03ddaa4]
#contents
*参考情報 [#le1a12d2]
-[[https://developer.apple.com/jp/devcenter/ios/library/documentation/RemoteNotificationsPG.pdf:https://developer.apple.com/jp/devcenter/ios/library/documentation/RemoteNotificationsPG.pdf]]…アップルのガイドPDF。

*基本 [#v8302655]
**通知の設定 [#bed38034]
-UILocalNotificationを生成し、UIApplicationに登録する
#pre{{
    UILocalNotification *notification = [[UILocalNotification alloc] init];
    //通知日時
    notification.fireDate = [[NSDate date] addTimeInterval:5];
    //タイムゾーン
    notification.timeZone = [NSTimeZone defaultTimeZone];
    //メッセージ
    notification.alertBody = @"Notification";
    //アクション
    notification.alertAction = @"Open";
    //サウンド
    notification.soundName = UILocalNotificationDefaultSoundName;
    [[UIApplication sharedApplication] scheduleLocalNotification:notification];
}}
**通知のキャンセル [#j852b451]
-全ての通知をキャンセルする場合
#pre{{
    [[UIApplication sharedApplication] cancelAllLocalNotifications];

}}


**フォアグラウンドでアプリが起動中の場合の通知の受信 [#sf009011]
-AppDelegateの以下のメソッドで受信できる
#pre{{
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
    NSLog(@"LocalNotification Received");
}
}}

-アラートやバナーは表示されないけど、バイブと音だけはくる?
**バックグラウンドでアプリが起動中の場合 [#y9b6b2fd]
-バナーやアラートのボタンをクリックしてアプリを再表示したときだけdidReceiveLocalNotificationが呼ばれる。
-ボタンが押されなかったときは(ユーザーからのアクションがなかったときは)何も通知されないらしい。

**起動していない場合 [#gee04219]
-バナーやアラートのボタンをクリックしてアプリを再表示したときだけdidFinishLaunchingWithOptionsが呼ばれる。引数で区別できる。
-ボタンが押されなかったときは何も通知されないらしい。


*トラブルシューティング [#e0e1a339]
**通知の見た目を変えたい [#a7d7cf8d]
-アプリごとにバーナーやアラートなど通知のスタイルを設定画面で設定できる。しかしこれはプログラムには解放されてない?
-[[iphone - UILocalNotification not firing when the app is in working mode - Stack Overflow:http://stackoverflow.com/questions/11220237/uilocalnotification-not-firing-when-the-app-is-in-working-mode]]

トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS