




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
【移動(dòng)應(yīng)用開發(fā)技術(shù)】IOS8本地推送補(bǔ)充
--(BOOL)application:(UIApplication
*)applicationdidFinishLaunchingWithOptions:(NSDictionary
*)launchOptions{
//Overridepointforcustomizationafterapplicationlaunch.
_window
=[[UIWindow
alloc]initWithFrame:[UIScreen
mainScreen].bounds];
_window.backgroundColor
=[UIColor
whiteColor];
[_window
makeKeyAndVisible];
ScrollContentViewController
*scrollcontentView=[[ScrollContentViewController
alloc]init];
UINavigationController
*navigationController=[[UINavigationController
alloc]initWithRootViewController:scrollcontentView];
_window.rootViewController
=navigationController;
UIView
*statusBarView=[[UIView
alloc]initWithFrame:CGRectMake(0,-20,
320,
64)];
statusBarView.backgroundColor
=[UIColor
colorWithRed:0
green:122/255.0f
blue:247/255.0f
alpha:1];
[navigationController.navigationBar
addSubview:statusBarView];
[application
setStatusBarHidden:NO];
[application
setStatusBarStyle:UIStatusBarStyleLightContent];
//注冊推送(ios8)
if
([UIApplication
instancesRespondToSelector:@selector(registerUserNotificationSettings:)])
{
[[UIApplication
sharedApplication]registerUserNotificationSettings:[UIUserNotificationSettingssettingsForTypes:UIUserNotificationTypeAlert
|UIUserNotificationTypeBadge
|
UIUserNotificationTypeSound
categories:nil]];
}
return
YES;}
-(void)application:(UIApplication
*)applicationdidReceiveLocalNotification:(UILocalNotification
*)notification{
//接受本地推送
NSLog(@"%@",notification);
UIAlertView
*alert=[[UIAlertView
alloc]initWithTitle:@"iWeibo"
message:notification.alertBody
delegate:nil
cancelButtonTitle:@"確定"otherButtonTitles:
nil];
[alert
show];
//圖標(biāo)上的數(shù)字減1
application.applicationIconBadgeNumber
-=1;
//解除本地推送
//獲得uiapplication
UIApplication
*app=[UIApplication
sharedApplication];
//獲取本地推送數(shù)組
NSArray
*localArray=[app
scheduledLocalNotifications];
//聲明本體通知對象
UILocalNotification
*localNotification;
if
(localArray)
{
for
(UILocalNotification
*noti
in
localArray)
{
NSDictionary
*dict=noti.userInfo;
if
(dict)
{
NSString
*inKey=[dict
objectForKey:@"key"];
if
([inKey
isEqualToString:@"對應(yīng)的key值"])
{
if
(localNotification)
{
localNotification=
nil;
}
break;
}
}
}
//判斷是否找到已經(jīng)存在的相同key的推送
if
(!localNotification)
{
//不存在初始化
localNotification=[[UILocalNotification
alloc]init];
}
if
(localNotification)
{
//不推送取消推送
[app
cancelLocalNotification:localNotification];
return;
}
}}-(void)viewDidLoad
{}-(void)SendNotification:(UIButton
*)sender{
//創(chuàng)建本地推送
NSDate
*now=[NSDate
date];
UILocalNotification
*reminderNotification=[[UILocalNotification
alloc]init];
//設(shè)置推送時(shí)間
[reminderNotification
setFireDate:[now
dateByAddingTimeInterval:10]];
//設(shè)置時(shí)區(qū)
[reminderNotification
setTimeZone:[NSTimeZone
defaultTimeZone]];
//設(shè)置userinfo方便在之后需要撤銷的時(shí)候使用
reminderNotification.userInfo
=[NSDictionary
dictionaryWithObject:@"name"
forKey:@"key"];
//設(shè)置推送內(nèi)容
[reminderNotification
setAlertBody:@"Don'tforgettoShowOut!"];
[reminderNotification
setAlertAction:@"ShowOut"];
[reminderNotification
setCategory:@"alert"];
//設(shè)置推送聲音
[reminderNotification
setSoundName:UILocalNotificationDefaultSoundName];
//顯示在icon上的紅色圈子的數(shù)子
[reminderNotification
setApplicationIconBadgeNumber:1];
//添加推送到UIApplication
[[UIApplication
sharedApplication]scheduleLocalNotification:reminderNotification];
NSLog(@"currentUserNotificationSettings=%@",[[UIApplication
sharedApplication]currentUserNotificationSettings]);
[[UIApplication
sharedApplication]
isRegisteredForRemoteNotifications
];
UIAlertView
*successAlert=[[UIAlertView
alloc]initWithTitle:@"Reminder"
message:@"YourReminderhasbeenScheduled"
delegate:nilcancelButtonTitle:@"OKThanks!"
otherButtonTitles:
nil];
[successAlert
show];
}IOS8定位問題
/**
*1:先在info.plist中添加NSLocationAlwaysUsageDescription設(shè)置為字符串類型,為YES;
*2:在info.plist中添加NSLocationWhenInUseUsageDescription設(shè)置為字符串類型,為YES;
*3:創(chuàng)建CLLocationManager對象
*4:
//創(chuàng)建對象
*
self.locationManager=[[CLLocationManageralloc]init];
*
//設(shè)置代理
*
self.locationManager.delegate=self;
*
//請求
*
[self.locationManager
requestWhenInUseAuthorization];
*
//類型
*
self.locationManager.desiredAccuracy=kCLDistanceFilterNone;
*
//開始
*
[self.locationManager
startUpdatingLocation];
*5:寫代理方法-(void)locationManager:(CLLocationManager*)managerdidChangeAuthorizationStatus:(CLAuthorizationStatus)status
*/
//創(chuàng)建對象
self.locationManager=[[CLLocationManager
alloc]init];
//設(shè)置代理
self.locationManager.delegate=self;
//請求
[self.locationManager
requestAlwaysAuthorization];
//類型
self.locationManager.desiredAccuracy=kCLDistanceFilterNone;
//開始定位
[self.locationManager
startUpdatingLocation];
#pragmamark
代理方法//此方法會(huì)在用戶授權(quán)狀態(tài)改變時(shí)調(diào)用-(void)locationManager:(CLLocationManager
*)managerdidChangeAuthorizationStatus:(CLAuthorizationStatus)status{
switch
(status)
{
case
kCLAuthorizationStatusNotDetermined:
if
([self.locationManager
respondsToSelector:@selector(requestWhenInUseAuthorization)])
{
[self.locationManager
requestAlwaysAuthorization];
}
break;
default:
break;
}}
//更新位置的代理方法-(void)locationManager:(CLLocationManager
*)managerdidUpdateLocations:(NSArray*)locations{
//uselocations
NSLog(@"=========%@",locations);
//根據(jù)
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025屆四川省綿陽市部分校中考生物對點(diǎn)突破模擬試卷含解析
- 農(nóng)戶鏟車出售合同范例
- 代理勞務(wù)派遣工合同范例
- 出租單價(jià)合同范例
- 第三單元 第1節(jié) 溫度 教學(xué)設(shè)計(jì)- 2024-2025學(xué)年人教版物理 八年級上冊
- 勞務(wù)總包合同范本
- 因材施教的個(gè)性化教育計(jì)劃
- 城建行業(yè)保安工作總結(jié)計(jì)劃
- 前臺文員的職業(yè)培訓(xùn)與發(fā)展路徑計(jì)劃
- 分析不同財(cái)務(wù)工具的適用場景計(jì)劃
- 貝利嬰幼兒發(fā)展量表
- 血液透常見并發(fā)癥及處理課件
- 全國中小學(xué)幼兒園教職工安全素養(yǎng)培訓(xùn)課程試題
- 長輸管道工程施工組織設(shè)計(jì)
- 說課比賽一等獎(jiǎng)《醫(yī)用化學(xué)》說課課件
- 靜設(shè)備安裝課件(PPT 91頁)
- 英格索蘭空壓機(jī)知識
- 2022年度高等學(xué)??茖W(xué)研究優(yōu)秀成果獎(jiǎng)(科學(xué)技術(shù))提名工作手冊
- 完整版地下人防工程施工方案
- (完整word版)格拉布斯(Grubbs)臨界值表
- 汽車離合器的檢測與維修畢業(yè)論文
評論
0/150
提交評論