我正在使用本地通知,但我想在警报的邮件正文中放置一个图像.我怎样才能做到这一点?
我想要实现地理定位通知,如应用提醒.这就是我已经做过的事情:
在App代表中:
self.locationManager = [[[CLLocationManager alloc] init] autorelease]; /* don't leak memeory! */
[self.locationManager setDelegate:self];
[self.locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
-(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
}
-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
{
}
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
}
Run Code Online (Sandbox Code Playgroud)
并且视图控制器中的这一个开始监视:
CLLocationCoordinate2D location2D = mapView.region.center;
CLRegion *regionForMonitoring = [[CLRegion alloc] initCircularRegionWithCenter:location2D radius:1 identifier:@"RegionIdentifier"];
[[Utils getLocationManager] startMonitoringForRegion:regionForMonitoring];
Run Code Online (Sandbox Code Playgroud)
现在我不知道我需要做些什么才能使用这些信息来发送本地通知.
reminders mkmapview cllocationmanager ios uilocalnotification
我正在开发一个iOS应用程序,我必须得到本地通知,但是在应用程序状态不活动的情况下.当应用程序处于后台状态时,我成功收到通知.那么,当应用程序处于非活动状态时,是否可以获得本地通知?或者也许只有使用推送通知才有可能?
此致,亚美尼亚
如何将NSDate秒转换为秒?我需要它在几秒钟内,以便我可以添加30秒到日期,然后转换回来NSDate安排本地通知.任何更好的方法也是受欢迎的.
我是iOS技术的新手.我正在尝试使用UILocalNotification使用swift 2.0构建一个警报应用程序.当我点击按钮时,我从UIPickerView获取时间和日期.我也想显示通知和播放声音.但声音和通知都不起作用.请帮我!
@IBOutlet weak var myPickerView: UIDatePicker!
override func viewDidLoad() {
super.viewDidLoad()
myPickerView.date = NSDate()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func setAlarmClicked(sender: UIButton) {
let dateFormater : NSDateFormatter = NSDateFormatter()
dateFormater.timeZone = NSTimeZone.defaultTimeZone()
dateFormater.timeStyle = .ShortStyle
dateFormater.dateStyle = .ShortStyle
let dateTimeString : NSString = dateFormater.stringFromDate(myPickerView.date)
print("date is \(dateTimeString)")
self.sheduleLocalNotificationWithDate(myPickerView.date)
}
@IBAction func cancelAlarmClicked(sender: UIButton) {
}
func sheduleLocalNotificationWithDate(fireDate : NSDate){
let localNotification : UILocalNotification = UILocalNotification()
localNotification.fireDate = …Run Code Online (Sandbox Code Playgroud) 我想在应用程序处于forground时显示通知.下面是我为新的usernotificationdelegate方法所做的代码.
在app委托中:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.0")) {
//iOS 10 handling
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert) completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (!error) {
NSLog(@"request authorization succeeded!");
} }];
}
}
#pragma mark - User notification delegate
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
NSLog(@"willPresentNotification");
NSLog(@"%@", notification.request.content.userInfo);
completionHandler (UNNotificationPresentationOptionAlert);
}
Run Code Online (Sandbox Code Playgroud)
这是我触发本地通知的方法
-(void) fireLocalNotification:(NSString *) message
{
NSLog(@"fire Local Notification");
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.0")) {
//Notification Content …Run Code Online (Sandbox Code Playgroud) objective-c ios uilocalnotification unusernotificationcenter
可以UILocalNotification存放NSUserDefaults吗?
我试图获取值但它总是返回null.
这是尝试获取值的方法
-(IBAction)doneClicked:(id)sender
{
NSUserDefaults *prefx = [NSUserDefaults standardUserDefaults];
UILocalNotification *oldNotifObj = [prefx objectForKey:@"NotificationObject"];
NSLog(@"oldNotifObj = %@",oldNotifObj);
NSLog(@"enable notification");
if (oldNotifObj == nil)
{
[self addNotification];
NSLog(@"add a new one");
}
else
{
//if notification exist, remove old one, and add new one.
[self removeNotification:oldNotifObj];
[prefx setObject:nil forKey:@"NotificationObject"];
[self addNotification];
NSLog(@"remove old notification and add a new one");
}
}
Run Code Online (Sandbox Code Playgroud)
这是addNotification方法
-(void)addNotification
{
//set the notification
UILocalNotification *localNotif = [[UILocalNotification alloc]init];
localNotif.fireDate = …Run Code Online (Sandbox Code Playgroud) 
我在我的设置"应用程序不在后台运行" info.plist,所以当用户点击主页按钮时,应用程序退出.
当我 [UIApplication -appWillTerminate:]打电话时,我会向系统安排64个本地通知,所有这些都是不重复的.
但在带有iOS6.0.1的iPhone4上花费了相当长的时间(6.17秒).当我查看时间分析器时,我发现曲线非常奇怪,它不占用太多CPU时间,但确实需要花费很多时间.
此外,当我查看调用树时,93%的时间花费在[UIApplication -scheduleLocalNotification:]图像中显示的时间范围内.为什么?
这是我生成通知的方式:
UILocalNotification *n = [[[UILocalNotification] alloc] init] autorelease];
n.alertBody = @"some body";
n.hasAction = YES;
n.alertAction = @"some action";
n.fireDate = @"some date";
n.repeatInterval = 0;
n.soundName = @"my sound"
n.userInfo = aDictionaryWithAStringAbount10CharacterLongAnd2NSNumber.
[self.notifications addObject:n];
Run Code Online (Sandbox Code Playgroud)
这是我安排通知的方式:
-(void)endProxyAndWriteToSystemLocalNotification
{
_proxying = NO;
NSDate *dateAnchor = [NSDate date];
NSEnumerator *enumerator = [self.notifications objectEnumerator];
NSInteger i = 0;
while (i < maxLocalNotifCount) {
UILocalNotification *n = [enumerator nextObject];
if (!d) { …Run Code Online (Sandbox Code Playgroud) 我有一个方法,使UILocalNotification存储:
- (void)save:(NSString *)program at:(NSDate*)date {
NSLog(@"date to save: %@", date);
// NSLog(@"timezone: %@",[date descriptionWithLocale:[NSLocale systemLocale]]);
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
NSLog(@"date to fire: %@", date);
localNotification.fireDate = date;
NSString *s=[program stringByAppendingString:@" is now on "];
NSString *title=[s stringByAppendingString:channel];
localNotification.alertBody = title;
localNotification.alertAction = @"Show...";
//localNotification.timeZone = [NSTimeZone localTimeZone];
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
NSLog(@"notification to save %@",localNotification);
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
// Request to reload table view data
[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadData" object:self];
// Dismiss the view controller …Run Code Online (Sandbox Code Playgroud) 我正在尝试以1天(24小时)的时间间隔显示本地通知并且其工作正常,但现在我想取消特定日期的通知.我试过(今天)这个,但它似乎没有用.我的通知仍然显示这是我为取消通知所做的工作:
let appNotification = appDelegate!.notification
UIApplication.sharedApplication().cancelLocalNotification(appNotification)
Run Code Online (Sandbox Code Playgroud)
这是我如何安排通知appDelegate:
//scheduling notification
dateComp.year = 2015;
dateComp.month = 01;
dateComp.day = 20;
dateComp.hour = 21;
dateComp.minute = 05;
dateComp.timeZone = NSTimeZone.systemTimeZone()
notification.category = "FIRST_CATEGORY"
notification.alertBody = "my daily notiification ?"
notification.soundName = UILocalNotificationDefaultSoundName
notification.fireDate = finalFireDate
notification.repeatInterval = NSCalendarUnit.Day
let dateNow = NSDate()
let noticalendar = NSCalendar.currentCalendar()
let hour = calendar.component(NSCalendarUnit.Hour, fromDate: dateNow)
UIApplication.sharedApplication().scheduleLocalNotification(notification)
Run Code Online (Sandbox Code Playgroud)
我不知道为什么我不能取消通知有任何遗漏或做错的事,请告诉我.
ios ×10
cocoa-touch ×3
iphone ×2
objective-c ×2
swift2 ×2
alarm ×1
mkmapview ×1
nsdate ×1
performance ×1
reminders ×1
swift ×1