iPhone App - Generate Alert Popups when App is Closed

前端 未结 4 595
再見小時候
再見小時候 2021-01-15 05:34

In creating an iPhone app, is it possible to generate a popup alert on the iphone (similar to a Push notification) when the app has been closed. A simple example would be t

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-15 05:55

    You can do it now! And it's really rather simple. Create a UILocalNotification.

    UILocalNotification *localNotification = [[UILocalNotification alloc] init];
            if (localNotification == nil)
                return;
    //Initialise notification
            localNotification.fireDate = yourDate;
            localNotification.timeZone = [NSTimeZone defaultTimeZone];
            localNotification.alertBody = [NSString stringWithFormat:NSLocalizedString(@"Hey, you've forgotten something", nil)];
            localNotification.alertAction = [NSString stringWithFormat:NSLocalizedString(@"%@", nil), buttonTitle];
            localNotification.soundName = UILocalNotificationDefaultSoundName;
            [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
            [warningDate release];
            [localNotification release];
    

提交回复
热议问题