开发指南
Combo SDK 集成了友盟推送 SDK,游戏如需接入此功能,需联系世游运营人员申请开通此功能。我们会协助在友盟管理后台创建应用,并配置相关参数。 在对应的发行版本下启用友盟推送 SDK 功能模块后,需要使用 Combo CLI 工具重新生成项目构建数据。
支持平台
提示
- Android:启用推送通知功能,无需额外处理
- iOS:启用推送通知功能,需要在导出的 Xcode 工程中将
./Classes/Preprocessor.h
文件中宏UNITY_USES_REMOTE_NOTIFICATIONS
值更改为 1,否则将无法接收推送通知
iOS 富文本推送
iOS 平台默认只支持普通文本推送,若需推送图片富文本,则需要在 Xcode 中添加 Notification Service Extension,请按如下步骤进行配置:
1. 创建 Notification Service Extension
Target
- 首先我们创建一个Notification Service Extension,具体步骤如下:File——>New——>Target——->Notification Service Extension
- 命名创建的 Notification Service Extension 中有三个文件,如下图所示
2. 对 NotificationService 进行签名
注意: BundleID 的前缀需要和 Unity-iPhone 的 BundleID 保持一致,否则会报签名错误
3. 修改 Minimum Deployments 版本号
注意:请与 Unity-iPhone Target Minimum Deployments
保持一致
4. 添加 UserNotifications.framework
系统依赖库
5. 修改 Architectures 为 arm64
6. 将下方代码拷贝到 NotificationService.m
中
NotificationService.m
#import "NotificationService.h"
@interface NotificationService ()
@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;
@end
@implementation NotificationService
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
self.contentHandler = contentHandler;
self.bestAttemptContent = [request.content mutableCopy];
NSDictionary*apsDic =[request.content.userInfo objectForKey:@"aps"];
NSString*attachUrl =[apsDic objectForKey:@"image"];
NSString*category =[apsDic objectForKey:@"category"];
self.bestAttemptContent.categoryIdentifier = category;
NSURLSession*session =[NSURLSession sharedSession];
NSURL *url =[NSURL URLWithString:attachUrl];
NSURLSessionDownloadTask*downloadTask =[session downloadTaskWithURL:url
completionHandler:^(NSURL *_Nullable location,
NSURLResponse*_Nullable response,
NSError*_Nullable error){
NSString*caches =[NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask, YES) lastObject];
NSString*file =[caches stringByAppendingPathComponent:response.suggestedFilename];
NSFileManager*mgr =[NSFileManager defaultManager];
[mgr moveItemAtPath:location.path toPath:file error:nil];
if(file &&![file isEqualToString:@""])
{
UNNotificationAttachment*attch=[UNNotificationAttachment attachmentWithIdentifier:@"photo" URL:[NSURL URLWithString:[@"file://" stringByAppendingString:file]] options:nil error:nil];
if(attch)
{
self.bestAttemptContent.attachments =@[attch];
}
}
self.contentHandler(self.bestAttemptContent);
}];
[downloadTask resume];
}
- (void)serviceExtensionTimeWillExpire {
// Called just before the extension will be terminated by the system.
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
self.contentHandler(self.bestAttemptContent);
}
@end