2014-11-23 137 views
0

我有點困惑,如果我必須這樣做,或系統: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 ! 
+0

安排本地通知。 – nhgrif 2014-11-23 16:22:51

+0

怎麼樣?我知道它很簡單,我只是無法在google上找到它。 – Curnelious 2014-11-23 16:27:39

回答

0

你可以嘗試這樣的事情。這將安排一個本地通知在設定的日期和時間觸發(您需要提供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]; 
} 
相關問題