1.需要配合龙图baseSDK使用。
3.接入龙图iOSSDK后,需要配置firebase需要的依赖库。
1.需要配置的参数同firebase统计和谷歌登录参数一致;
2.需要添加的GoogleService-Info.plist文件同firebase统计使用的是同一个文件。
下载对应demo
1、需要引入的三方库
2、必须在 Xcode Build Settings 里面 Other Linker Flags 设置值 -ObjC。
该项如果设置错误,运行时就会出现异常:unrecognized selector sent to instance exception
3、设置SDK所需权限, 在项目工程的 signing&capabilities 中增加权限:
首先需要引入SDK:
#import <LTFIRMessagingSDK/LTFIRMessagingSDK.h>
接口:
/// 生命周期/// - Parameters:/// - application: application/// - launchOptions: launchOptions- (BOOL)LTFIRMessagingApplication:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
示例:
[[LTFIRMessagingSDK ShareInstance] LTFIRMessagingApplication:application didFinishLaunchingWithOptions:launchOptions];
接口:
/// 处理通知/// - Parameter message: 应用程序接收的下行消息- (void)LTFIRMessagingAppDidReceiveMessage:(NSDictionary *)message;
示例:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{[[LTGameOCSDK shareInstance] LTSDKApplication:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];[[LTFIRMessagingSDK ShareInstance] LTFIRMessagingAppDidReceiveMessage:userInfo];completionHandler(UIBackgroundFetchResultNewData);}- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{[[LTGameOCSDK shareInstance] LTSDKApplication:application didReceiveRemoteNotification:userInfo];// LTGameSDK::GetInstance().DidReceiveRemoteNotification(application, userInfo);[[LTFIRMessagingSDK ShareInstance] LTFIRMessagingAppDidReceiveMessage:userInfo];}
接口:
/// 获取deviceToken/// - Parameter deviceToken: 推送deviceToken- (void)LTFIRMessagingSetDeviceToken:(NSData *)deviceToken;
示例:
// 通知相关声明周期- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{const unsigned *tokenBytes = (const unsigned *)[deviceToken bytes];NSString *strToken = [NSString stringWithFormat:@"%08x%08x%08x%08x%08x%08x%08x%08x",ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];NSLog(@"deviceToken1:%@", strToken);[[LTFIRMessagingSDK ShareInstance] LTFIRMessagingSetDeviceToken:deviceToken];[[LTGameOCSDK shareInstance] LTSDKApplication:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];}
接口:
/// 获取本地FCMToken- (NSString *)LTFIRMessagingGetFCMToken;
示例:
NSString *strToken = [[LTFIRMessagingSDK ShareInstance] LTFIRMessagingGetFCMToken];
接口:
/// 设置主题/// - Parameter topic: 主题- (void)LTFIRMessagingSubscribeToTopic:(NSString *)topic;
示例:
[[LTFIRMessagingSDK ShareInstance] LTFIRMessagingSubscribeToTopic:主题];
接口:
/// 获取当前的FCMToken- (void)LTFIRMessagingGetFCMTokenMessage;
示例:
[[LTFIRMessagingSDK ShareInstance] LTFIRMessagingGetFCMTokenMessage];此接口前提需注册获取fcmtoken通知,调用此接口后会自动发送通知[[NSNotificationCenter defaultCenter] addObserver:selfselector:@selector(FIRMessagingFCMTokenNotification:)name:@"LTFIRMessagingFCMTokenNoti"object:nil];- (void)FIRMessagingFCMTokenNotification:(NSNotification *)noti{NSDictionary *dict = noti.object;NSString *token = [dict objectForKey:@"message"];NSLog(@"token1 = %@",token);}
示例:
此接口前提需注册fcmtoken刷新的通知[[NSNotificationCenter defaultCenter] addObserver:selfselector:@selector(FIRMessagingReceiveNotification:)name:@"LTFIRMessagingdidReceiveNoti"object:nil];该通知会在token每次刷新后自动发送- (void)FIRMessagingReceiveNotification:(NSNotification *)noti{NSDictionary *dict = noti.object;NSString *token = [dict objectForKey:@"fcmToken"];NSLog(@"token2 = %@",token);}

上海中清龙图软件有限公司