您好,登錄后才能下訂單哦!
- (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];
// 為了復用代碼,統一到下面這個處理方法中handlePushNotify:
[self handlePushNotify:dic fromBuld:_ISPushFromClosed]; //如果程序沒有啟動,點擊推送消息進入程序,需要根據推送消息做一些處理,如:視圖切換等。
}
//注冊遠程推送,成功后的代理方法
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
//蘋果服務器返回的token (蘋果服務器用來標識手機的唯一編號)
//可以交給后臺,然后后臺需要給此發送遠程推送的時候直接用這個token
NSString *tokenStr = [deviceToken description];
NSLog(@"token:%@",tokenStr);
}
//注冊遠程推送失敗
-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSLog(@"注冊推送失敗%@",error);
}
//程序正在運行時,點擊推送消息所走的方法
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
//在這里可以根據推送信息做一些操作
[self handlePushNotify:userInfo fromBuld:_ISPushFromOpen];
}
-(void)handlePushNotify:(NSDictionary *)dic fromBuld:(NSString *)buld
{
// 根據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";
};
};
*/
}
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。