【移動(dòng)應(yīng)用開發(fā)技術(shù)】IOS 8 本地推送補(bǔ)充_第1頁
【移動(dòng)應(yīng)用開發(fā)技術(shù)】IOS 8 本地推送補(bǔ)充_第2頁
【移動(dòng)應(yīng)用開發(fā)技術(shù)】IOS 8 本地推送補(bǔ)充_第3頁
【移動(dòng)應(yīng)用開發(fā)技術(shù)】IOS 8 本地推送補(bǔ)充_第4頁
【移動(dòng)應(yīng)用開發(fā)技術(shù)】IOS 8 本地推送補(bǔ)充_第5頁
已閱讀5頁,還剩3頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論