1.倒入百度 SDK 第三方包
2.添加依赖框架:
LibZ.dylib
CoreGraphics.frameWork
CoreTelePhony.framework
SystemConfiguration.framework
3.添加百度SDK所依赖的JSONKit 第三方文件 并对jsonKit 禁arc处理。
做完如上的三步就开始代码的实现了:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
[[UINavigationBar appearance] setTintColor:[UIColor grayColor]];
[application setStatusBarHidden:YES];
// iOS8 下需要使用新的 API
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
UIUserNotificationType myTypes = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:myTypes categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}else {
UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound;
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes];
}
#warning 上线 AppStore 时需要修改 pushMode
// 在 App 启动时注册百度云推送服务,需要提供 Apikey
[BPush registerChannel:launchOptions apiKey:@"your keys" pushMode:BPushModeDevelopment isDebug:YES];
// [BPush setupChannel:launchOptions];
// 设置 BPush 的回调
[BPush setDelegate:self];
// App 是用户点击推送消息启动
NSDictionary *userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (userInfo) {
NSLog(@"从消息启动:%@",userInfo);
[BPush handleNotification:userInfo];
}
return YES;
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
// 打印到日志 textView 中
// [self.viewController addLogString:[NSString stringWithFormat:@"backgroud : %@",userInfo]];
completionHandler(UIBackgroundFetchResultNewData);
}
// 在 iOS8 系统中,还需要添加这个方法。通过新的 API 注册推送服务
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
[application registerForRemoteNotifications];
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSLog(@"test:%@",deviceToken);
[BPush registerDeviceToken:deviceToken];
[BPush bindChannel];
// 打印到日志 textView 中
// [self.viewController addLogString:[NSString stringWithFormat:@"Register use deviceToken : %@",deviceToken]];
}
// 当 DeviceToken 获取失败时,系统会回调此方法
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
NSLog(@"DeviceToken 获取失败,原因:%@",error);
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
// App 收到推送的通知
[BPush handleNotification:userInfo];
// [self.viewController addLogString:[NSString stringWithFormat:@"Received Remote Notification :\n%@",userInfo]];
NSLog(@"%@",userInfo);
}
#pragma mark Push Delegate
- (void)onMethod:(NSString*)method response:(NSDictionary*)data
{
// [self.viewController addLogString:[NSString stringWithFormat:@"Method: %@\n%@",method,data]];
}
分享到:
相关推荐
百度云推送支持多种平台,包括Android和iOS。 3. **Cordova插件机制**:Cordova插件是连接JavaScript和原生平台之间的桥梁。开发者可以通过插件来调用设备的原生功能,如相机、地理位置、推送通知等。这个插件实现...
这个创新项目结合了人工智能和音乐娱乐,通过识别人脸情绪来推送相应的音乐,或者根据情绪改变界面,以提供个性化的音乐体验。以下是文档中涉及的关键知识点: 1. **HTML5**: HTML5是一种超文本标记语言的最新版本...
以上只是部分介绍,实际上这份API合集覆盖了众多领域,如电商、地图、电影、即时通讯、开发者网站、快递查询、旅游、社交、视频、天气、团队协作、图片与图像处理、外卖、消息推送、音乐、云计算、语音识别和综合类...
- 推送服务:极光推送、华为推送等 - 图片/文件存储:七牛云、阿里云OSS - 第三方登录SDK接入:微信开放平台、QQ互联 #### 五、安装步骤说明 1. **下载源码包**:从百度网盘获取资源(链接见上文),并使用提取...
东南大学、中国科学技术信息研究所、国家图书馆有权保留本人所送交学位论文的复印件和电子文档,可以采用影印、缩印或其他复制手段保存论文。本人电子文档的内容和纸质论文的内容相一致。除在保密期内的保密论文和在...
客户端验证灵活稳定,服务器端升级统一分发部署,全面实时监控管理,企业自编信息快捷推送。 金山词霸Mac版 Mac OS X上最清爽的查词体验。收录现代汉英/英汉词典,可以实现单词朗读,还能学习同反义词。 发展历程...