iOS在后台发生什么事情时会显示通知?
问题描述:
我有点困惑,如果我必须这样做,或系统:iOS在后台发生什么事情时会显示通知?
使用iBeacon有一个方法,当应用程序在后台或关闭时触发。 在那里,我想写的代码将显示用户在iPhone主屏幕上的推送通知,让他知道它。
我会怎么做这么简单的事情?
//happens in background when user inside a place
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
[self.locationManager startRangingBeaconsInRegion:self.beaconRegion];
NSLog(@"***********************ENTER");
//here show notification !
答
你可以尝试这样的事情。这将安排一个本地通知在设定的日期和时间触发(您需要提供NSDate和消息)。
...
NSDate *fireDate = // whatever date and time you want to fire the notification
NSString alertMessage = @“Alert message!";
[self addNotification:fireDate mymessage:alertMessage];
...
-(void)addNotification:(NSDate *)mydate mymessage:(NSString *)mymessage
{
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = mydate;
localNotification.alertBody = mymessage;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}
安排本地通知。 – nhgrif 2014-11-23 16:22:51
怎么样?我知道它很简单,我只是无法在google上找到它。 – Curnelious 2014-11-23 16:27:39