日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ios 消息服务器,关于IOS APNS推送消息(iphone端+服务端)

發布時間:2024/9/27 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ios 消息服务器,关于IOS APNS推送消息(iphone端+服务端) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這兩天,項目要求做個推送功能,研究了一天,在此跟各位分享下。因為之前做了一年的php,所以服務端我自己寫的,php語言。

1:請求證書,APPID各種繁瑣的操作,我就不多話了,我也是看網上例子的。?http://luoyl.info/blog/2012/02/apple_push_notification_guide/

iphone端的代碼:

#define push_server @"http://192.168.0.123/push/apns.php"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

/** 注冊推送通知功能, */

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];

application.applicationIconBadgeNumber = 0;

//判斷程序是不是由推送服務完成的

if (launchOptions) {

NSDictionary* pushNotificationKey = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

if (pushNotificationKey) {

application.applicationIconBadgeNumber = 0;

}

}

}

/** 接收從蘋果服務器返回的唯一的設備token,然后發送給自己的服務端*/

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

NSString* devices_token = [NSString stringWithFormat:@"%@",deviceToken];

NSString* devices_name = [[UIDevice currentDevice] name];

NSString* devices_version = [[UIDevice currentDevice] systemVersion];

NSString* devices_type = [[UIDevice currentDevice] model];

NSString* mode = @"Development";

NSString *strUrl = [NSString stringWithFormat:@"%@?action=registerDevices&devices_token=%@&devices_name=%@&devices_version=%@&devices_type=%@&mode=%@",

push_server,devices_token,devices_name,devices_version,devices_type,mode];

strUrl = [strUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSURL *url = [NSURL URLWithString:strUrl];

NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];

//發送URL請求

NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];

}

//程序處于啟動狀態,或者在后臺運行時,會接收到推送消息,解析處理

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo

{

NSLog(@"

apns -> didReceiveRemoteNotification,Receive Data:

%@", userInfo);

//把icon上的標記數字設置為0,

application.applicationIconBadgeNumber = 0;

if ([[userInfo objectForKey:@"aps"] objectForKey:@"alert"]!=NULL) {

if(application.applicationState ==UIApplicationStateActive){

[self alertNotice:@"推送通知" withMSG:[[userInfo objectForKey:@"aps"] objectForKey:@"alert"] cancleButtonTitle:@"OK" otherButtonTitle:nil];

}

NSString *strUrl = [NSString stringWithFormat:@"%@?action=cleanBadgeNumber&id=%@&badge=%d",

push_server,[[userInfo objectForKey:@"aps"] objectForKey:@"id"],0];

strUrl = [strUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSURL *url = [NSURL URLWithString:strUrl];

NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];

//發送URL請求

NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];

}

}

php端代碼,下載附件,環境搭配:php+mysql

如果不明白的地方,上微博問我。http://weibo.com/1999711542/

總結

以上是生活随笔為你收集整理的ios 消息服务器,关于IOS APNS推送消息(iphone端+服务端)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。