友盟统计
开发前准备
SDK下载与文档链接: http://dev.umeng.com/analytics/ios-doc/integration
新建项目导入开发包
也可以用Cocoapods
pod 'UMengAnalytics'//标准SDK,含IDFA
pod 'UMengAnalytics-NO-IDFA'//无IDFA版SDK(请根据需要选择)
集成资源
开发
AppDelegate
中调用方法:
/** 初始化友盟统计模块
@param appKey 友盟appKey.
@param reportPolicy 发送策略, 默认值为:BATCH,即“启动发送”模式
@param channelId 渠道名称,为nil或@""时, 默认为@"App Store"渠道
@return void
*/
+ (void)startWithAppkey:(NSString *)appKey reportPolicy:(ReportPolicy)rp channelId:(NSString *)cid;
传入版本号:
/** 设置app版本号。由于历史原因需要和xcode3工程兼容,友盟提取的是Build号(CFBundleVersion),
如果需要和App Store上的版本一致,请调用此方法。
@param appVersion 版本号,例如设置成XcodeAppVersion
.
@return void.
*/
+ (void)setAppVersion:(NSString *)appVersion;
然后用什么功能看文档调用方法就好
友盟分享
开发前准备
SDK下载与文档链接:http://dev.umeng.com/social/ios/quick-integration
新建项目导入开发包:
还需要对应渠道的分包:
比如Wechat就是微信的分包.
开发
在以下方法中加入:+ (void)setAppKey:(NSString *)appKey;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[UMSocialData setAppKey:@"key"];
return YES;
}
具体使用方法可以参考文档
友盟推送
开发前准备
SDK下载与文档链接:http://dev.umeng.com/push/ios/integration
新建项目导入开发包
开发
在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
中添加如下代码.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[UMessage startWithAppkey:@"your appkey" launchOptions:launchOptions];
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= _IPHONE80_
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0 ){
//register remoteNotification types (iOS 8.0及其以上版本)
UIMutableUserNotificationAction *action1 = [[UIMutableUserNotificationAction alloc] init];
action1.identifier = @"action1_identifier";
action1.title=@"Accept";
action1.activationMode = UIUserNotificationActivationModeForeground;//当点击的时候启动程序
UIMutableUserNotificationAction *action2 = [[UIMutableUserNotificationAction alloc] init]; //第二按钮
action2.identifier = @"action2_identifier";
action2.title=@"Reject";
action2.activationMode = UIUserNotificationActivationModeBackground;//当点击的时候不启动程序,在后台处理
action2.authenticationRequired = YES;//需要解锁才能处理,如果action.activationMode = UIUserNotificationActivationModeForeground;则这个属性被忽略;
action2.destructive = YES;
UIMutableUserNotificationCategory *categorys = [[UIMutableUserNotificationCategory alloc] init];
categorys.identifier = @"category1";//这组动作的唯一标示
[categorys setActions:@[action1,action2] forContext:(UIUserNotificationActionContextDefault)];
UIUserNotificationSettings *userSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlert
categories:[NSSet setWithObject:categorys]];
[UMessage registerRemoteNotificationAndUserNotificationSettings:userSettings];
} else{
//register remoteNotification types (iOS 8.0以下)
[UMessage registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge
|UIRemoteNotificationTypeSound
|UIRemoteNotificationTypeAlert];
}
#else
//register remoteNotification types (iOS 8.0以下)
[UMessage registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge
|UIRemoteNotificationTypeSound
|UIRemoteNotificationTypeAlert];
#endif
//for log
[UMessage setLogEnabled:YES];
return YES;
}
注册远程通知:
application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
加入代码
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
[UMessage registerDeviceToken:deviceToken];
}
推送过来的消息进行处理的方法
application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
// 也可以不较高友盟处理 自己处理消息
[UMessage didReceiveRemoteNotification:userInfo];
}
需要注意的是[UMessage didReceiveRemoteNotification:userInfo];
不一定非要使用友盟的处理方法也可以自定义,userInfo
是服务器发过来的消息字典集合.