友盟分享,极光推送Demo
友盟分享SDK下载及官方文档
http://dev.umeng.com/social/ios/detail-share
1.注册应用获取App友盟Appkey(556d14ad67e58eb084003fed)
2.下载SDK并导入工程内
3.添加库文件
/友盟分享 注意添加类库 libz.1.1.3.dylib libstdc++.dylib /** 需添加类库 Security.framework libiconv.dylib SystemConfiguration.framework CoreGraphics.Framework libsqlite3.dylib CoreTelephony.framework libstdc++.dylib libz.dylib */
4.配置URL schemes
配置URL是为了能够分享到其他应用后能返回当前应用,不配置将无法返回
步骤:搜索plist,选择Inf.plist,添加一项URL types
添加相关Url(详细如何设置 URL schemes)
(相关扩展阅读 iOS 客户端URL Scheme配置以及使用)
添加相关代码
AppDelegate.h 文件
// // AppDelegate.h // UMShareTestDemo #import <UIKit/UIKit.h> #define UmengAppkey @"5513d956fd98c579b80003de" //友盟分享Key @interface AppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @end
AppDelegate.m 文件
// AppDelegate.m // UMShareTestDemo // // Created by luo.h on 15-6-2. // Copyright (c) 2015年 sibu.cn. All rights reserved. // #import "AppDelegate.h" #import "UMSocialWechatHandler.h"//微信分享 #import "UMSocialQQHandler.h" //QQ分享 #import "UMSocial.h"//友盟分享 注意添加类库 libz.1.1.3.dylib libstdc++.dylib /** 注意添加类库,否则报错 Security.framework libiconv.dylib SystemConfiguration.framework CoreGraphics.Framework libsqlite3.dylib CoreTelephony.framework libstdc++.dylib libz.dylib */ @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. [self UMSociaShareSetting];//UMShare return YES; } #pragma mark ---友盟分享相关设置 Beggin---- -(void)UMSociaShareSetting { [UMSocialData setAppKey:UmengAppkey];//友盟分享 //设置微信AppId、appSecret,分享url 微信,QQ [UMSocialWechatHandler setWXAppId:@"wx2cbecfee5bbcdca8" appSecret:@"e0b32875602ccbb7147c9e944807c39b" url:@"https://weishang.org/download/"]; [UMSocialQQHandler setQQWithAppId:@"1104521802" appKey:@"a1zNFkJ4IY76mu0A" url:@"https://weishang.org/download/"]; } - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { return [UMSocialSnsService handleOpenURL:url]; } - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { BOOL result = [UMSocialSnsService handleOpenURL:url]; if (result == FALSE) { //调用其他SDK,例如新浪微博SDK等 } return result; } #pragma mark ---友盟分享相关设置 End----
分享页面设置 ViewController
// // ViewController.m // UMShareTestDemo #import "ViewController.h" #import "AppDelegate.h"//UmengAppkey在AppDelegate里 #import "UMSocial.h" //UM分享 @interface ViewController ()<UMSocialUIDelegate> @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. UIButton *shareButton=[UIButton buttonWithType:UIButtonTypeCustom]; shareButton.frame=CGRectMake(100,100, 100, 80); shareButton.backgroundColor=[UIColor orangeColor]; [shareButton setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal]; [shareButton setTitle:@"UM分享" forState:UIControlStateNormal]; [shareButton addTarget:self action:@selector(UMShareUI) forControlEvents:UIControlEventTouchDown]; [self.view addSubview:shareButton]; } #pragma mark-------------- 友盟分享 ----------------- //友盟分享 -(void)UMShareUI { NSString *shareText = @"手机在手即可随时随地完成微商权威认证https://weishang.org/center/download"; //分享内嵌文字 UIImage *shareImage = [UIImage imageNamed:@"shareIcon"]; //分享内嵌图片 NSArray *arrayNames=[NSArray arrayWithObjects:UMShareToWechatSession,UMShareToWechatTimeline,UMShareToQQ,UMShareToQzone,UMShareToSina,UMShareToTencent,UMShareToSms,UMShareToDouban,nil]; //注意:分享到微信好友、微信朋友圈、微信收藏、QQ空间、QQ好友、来往好友、来往朋友圈、易信好友、易信朋友圈、Facebook、Twitter、Instagram等平台需要参考各自的集成方法 [UMSocialSnsService presentSnsIconSheetView:self appKey:UmengAppkey shareText:shareText shareImage:shareImage shareToSnsNames:arrayNames delegate:self]; } //弹出列表方法presentSnsIconSheetView需要设置delegate为self -(BOOL)isDirectShareInIconActionSheet { return NO;//NO 不直接分享 } -(void)didCloseUIViewController:(UMSViewControllerType)fromViewControllerType { NSLog(@"didClose is %d",fromViewControllerType); } //下面得到分享完成的回调 -(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response { NSLog(@"didFinishGetUMSocialDataInViewController with response is %@",response); //根据`responseCode`得到发送结果,如果分享成功 if(response.responseCode == UMSResponseCodeSuccess) { //得到分享到的微博平台名 NSLog(@"share to sns name is %@",[[response.data allKeys] objectAtIndex:0]); } else { NSLog(@"分享失败"); } } @end
PS:QQ空间必须为图文分享,否则分享失败
Demo下载 https://files.cnblogs.com/files/sixindev/UMShareTestDemo.zip
首先需要在开发者平台注册应用,获取APPID
QQ开放平台
微信开发平台
极光推送
iOS SDK 集成指南 http://docs.jpush.io/guideline/ios_guide/
iOS SDK 教程 http://docs.jpush.io/client/ios_tutorials/
极光测试推送Demo下载
里面有证书和描述文件,直接安装即可,极光推送账号为公用账号
iOS远程推送(APNS)测试工具
作者:SIBU iOS DEV
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.