我的應用程序正在使用谷歌地圖,它顯示了汽車方向,使用戶可以看到其移動地圖,我的問題是:1。 當用戶將應用程序在後臺我想要的NSTimer保持運行 2.雖然它在後臺,當我收到來自api的迴應,表示汽車已抵達,,我想發送本地通知,以便用戶可以看到它並打開應用程序如何在後臺接收到Api響應時使用本地通知?
這裏是一些代碼:
//here is the timer
searchTimer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(getLocationForDriver) userInfo:Nil repeats:YES];
-(void)getLocationForDriver
{
NSArray* pks = [NSArray arrayWithObject:self.driverPK];
[[NetworkEngine getInstance] trackBooking:pks completionBlock:^(NSObject* response)
{
NSDictionary* dict = (NSDictionary*)response;
currentStatus = [dict objectForKey:@"current_status"];
.
.
.
.
if ([currentStatus isEqualToString:@"completed"])
{
//here i want to send the local notification
}
}
}
那麼,這有助於解決計時器的第一個問題,但主要問題是如何發送通知時,收到使用UILocalnotification響應? – ghasso
查看我更新的答案 – Gad