gpt4 book ai didi

iphone - 当 App 处于后台模式时,UILocalNotification 可以触发自定义方法吗?

转载 作者:太空狗 更新时间:2023-10-30 03:29:12 24 4
gpt4 key购买 nike

好吧,标题是不言自明的。我想创建一个应用程序,当应用程序处于后台模式时,它可以管理编程的本地通知。通知工作顺利,但我想在触发警报时触发自定义方法。

这可能吗?谢谢。

最佳答案

是的,这是可以做到的。你可以这样做:

- (void)applicationDidEnterBackground:(UIApplication *)application {
[NSTimer scheduledTimerWithTimeInterval:17.0 target:self selector:@selector(makeNotificationRequest:) userInfo:nil repeats:YES];
}

-(void)makeNotificationRequest:(NSTimer *)timer
{
CLLocation *location = [[AppHelper appDelegate] mLatestLocation];
NSMutableDictionary *paramDic = [[NSMutableDictionary alloc] init];

#ifdef _DEBUG
[paramDic setValue:[NSString stringWithFormat:@"77.586"] forKey:@"Lat"];
[paramDic setValue:[NSString stringWithFormat:@"12.994"] forKey:@"long"];
#else
[paramDic setValue:[NSString stringWithFormat:@"%f",location.coordinate.latitude] forKey:@"Lat"];
[paramDic setValue:[NSString stringWithFormat:@"%f",location.coordinate.longitude] forKey:@"long"];
#endif

WNetwork *mNetwork = [[WNetwork alloc] init];
[mNetwork makeRequsetWithURL:URL_Showbeeps type:JBJsonParser paramDictionary:paramDic delegate:self];
[mNetwork autorelease];
NSLog(@"URL HIT%@",paramDic);
[paramDic autorelease];
}

要自定义警报时的操作,您可以使用:

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateActive) {
;
}
}

关于iphone - 当 App 处于后台模式时,UILocalNotification 可以触发自定义方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7903080/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com