您好,登錄后才能下訂單哦!
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
//注冊推送通知
// [[UIApplication sharedApplication]registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
//
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings
settingsForTypes:(UIUserNotificationTypeSound |
UIUserNotificationTypeAlert |
UIUserNotificationTypeBadge)
categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else {
[[UIApplication sharedApplication]registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert|
UIRemoteNotificationTypeBadge|
UIRemoteNotificationTypeSound];
}
if (launchOptions) {
// UIApplicationLaunchOptionsRemoteNotificationKey 這個key值就是push的信息
NSDictionary *dic = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
// 為了復(fù)用代碼,統(tǒng)一到下面這個處理方法中handlePushNotify:
[self handlePushNotify:dic fromBuld:_ISPushFromClosed]; //如果程序沒有啟動,點擊推送消息進入程序,需要根據(jù)推送消息做一些處理,如:視圖切換等。
}
//注冊遠程推送,成功后的代理方法
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
//蘋果服務(wù)器返回的token (蘋果服務(wù)器用來標識手機的唯一編號)
//可以交給后臺,然后后臺需要給此發(fā)送遠程推送的時候直接用這個token
NSString *tokenStr = [deviceToken description];
NSLog(@"token:%@",tokenStr);
}
//注冊遠程推送失敗
-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSLog(@"注冊推送失敗%@",error);
}
//程序正在運行時,點擊推送消息所走的方法
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
//在這里可以根據(jù)推送信息做一些操作
[self handlePushNotify:userInfo fromBuld:_ISPushFromOpen];
}
-(void)handlePushNotify:(NSDictionary *)dic fromBuld:(NSString *)buld
{
// 根據(jù)buld判斷是哪里傳來的值
/*
dic = {
aps = {
alert = "\U627e\U5927\U592b\U63d0\U793a\Uff1ahdf21\U7528\U6237\U7533\U8bf7\U52a0\U5165\U60a8\U7684\U5c0f\U680b\U5708\U5708\U5b50";
sound = default;
target = {
"param_list" = (
{
"param_name" = "circle_id";
"param_value" = 2204;
},
{
"param_name" = "circle_name";
"param_value" = "\U5c0f\U680b\U5708";
},
{
"param_name" = type;
"param_value" = 1;
}
);
topage = "/gooddoc/server/index.php/circle/getCircleMembersNews";
};
};
*/
}
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。