2

私は Xcode に比較的慣れていません。非常に単純な目覚まし時計を作成しています。以下はアプリの小さなスニペットです。私の質問は次のとおりです。アラームが発生したときにカスタムビュー(つまり、写真またはアニメーション)を表示し、その上に「閉じる」ボタンを配置する方法は?前もって感謝します

ニコラ

 - (void) scheduleLocalNotificationWithDate:(NSDate *)fireDate :(NSString *)message
 {
     UILocalNotification *notificaiton = [[UILocalNotification alloc] init];
     if (notificaiton == nil)
        return;
     notificaiton.fireDate = fireDate;
     notificaiton.alertBody = message;
     notificaiton.timeZone = [NSTimeZone defaultTimeZone];
     notificaiton.alertAction = @"View";
     notificaiton.soundName = @"alarm-clock-1.mp3";
     notificaiton.applicationIconBadgeNumber = 1;
     notificaiton.repeatInterval = kCFCalendarUnitWeekday;
     NSLog(@"repeat interval is %@",notificaiton.description);

     [[UIApplication sharedApplication] scheduleLocalNotification:notificaiton];
4

2 に答える 2

1

この方法を使用する

アプリの実行中に通知を処理する

- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif 
{
// show your custom alert view
}

通知からの起動を処理する

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

UILocalNotification *localNotif =
[launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotif) 
{
// show your custom alert view
}

return YES;
}
于 2013-07-17T13:13:42.237 に答える
0

アプリがバックグラウンドにある場合は、推奨される Kalpesh を使用できます。ただし、アプリケーションがフォアグラウンドにある場合、カスタム ビューを直接表示することはできません。アラートまたはカスタマイズされたアラートを表示し、そのアラートを受け入れると、カスタム ビューを表示できます。

于 2013-07-17T13:21:51.920 に答える