|
|
@@ -31,6 +31,7 @@ static NSString* umengAppMasterSecret = @"";
|
|
|
|
|
|
- (void)pluginInitialize
|
|
|
{
|
|
|
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveDeviceToken:) name:@"deviceToken" object:nil];
|
|
|
[UMConfigure setLogEnabled:true];
|
|
|
[UMConfigure initWithAppkey:umengKey channel:nil];
|
|
|
[UMCommonHandler setVerifySDKInfo:umengSecret complete:^(NSDictionary * _Nonnull resultDic) {
|
|
|
@@ -105,15 +106,78 @@ static NSString* umengAppMasterSecret = @"";
|
|
|
|
|
|
- (void)initPush:(CDVInvokedUrlCommand*)command
|
|
|
{
|
|
|
-// // Push组件基本功能配置
|
|
|
-// UMessageRegisterEntity * entity = [[UMessageRegisterEntity alloc] init];
|
|
|
-// //type是对推送的几个参数的选择,可以选择一个或者多个。默认是三个全部打开,即:声音,弹窗,角标
|
|
|
-// entity.types = UMessageAuthorizationOptionBadge|UMessageAuthorizationOptionSound|UMessageAuthorizationOptionAlert;
|
|
|
-// [UNUserNotificationCenter currentNotificationCenter].delegate = self.appDelegate;
|
|
|
-// [UMessage registerForRemoteNotificationsWithLaunchOptions:nil Entity:entity completionHandler:^(BOOL granted, NSError * _Nullable error) {
|
|
|
-// if (granted) {
|
|
|
-// }else{
|
|
|
-// }
|
|
|
-// }];
|
|
|
+ [[NSUserDefaults standardUserDefaults] setObject:command.callbackId forKey:@"initPushCallbackId"];
|
|
|
+ NSDictionary* launchOptions = [[NSUserDefaults standardUserDefaults] objectForKey:@"appLaunchOptions"];
|
|
|
+ // Push组件基本功能配置
|
|
|
+ UMessageRegisterEntity * entity = [[UMessageRegisterEntity alloc] init];
|
|
|
+ //type是对推送的几个参数的选择,可以选择一个或者多个。默认是三个全部打开,即:声音,弹窗,角标
|
|
|
+ entity.types = UMessageAuthorizationOptionBadge|UMessageAuthorizationOptionSound|UMessageAuthorizationOptionAlert;
|
|
|
+ [UMessage registerForRemoteNotificationsWithLaunchOptions:launchOptions Entity:entity completionHandler:^(BOOL granted, NSError * _Nullable error) {
|
|
|
+ if (granted) {
|
|
|
+ NSLog(@"registerForRemoteNotifications granted");
|
|
|
+ }else{
|
|
|
+ NSLog(@"registerForRemoteNotifications not granted");
|
|
|
+ }
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)receiveDeviceToken:(NSNotification *)notification
|
|
|
+{
|
|
|
+ NSString* deviceToken = notification.object;
|
|
|
+ NSString* callbackId = [[NSUserDefaults standardUserDefaults] objectForKey:@"initPushCallbackId"];
|
|
|
+ if(callbackId){
|
|
|
+ [self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:deviceToken] callbackId:callbackId];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void) shareImg:(CDVInvokedUrlCommand*)command
|
|
|
+{
|
|
|
+ UMSocialMessageObject* messageObject = [UMSocialMessageObject messageObject];
|
|
|
+
|
|
|
+ NSDictionary* data = command.arguments[0];
|
|
|
+ NSString* imgUrl = data[@"imgUrl"];
|
|
|
+ NSString* thumb = data[@"thumb"];
|
|
|
+ NSString* platform = data[@"platform"];
|
|
|
+
|
|
|
+ UMShareImageObject* shareObject = [self toImg:imgUrl];
|
|
|
+ if (thumb) {
|
|
|
+ shareObject.thumbImage = [self toImg:thumb];
|
|
|
+ }
|
|
|
+ messageObject.shareObject = shareObject;
|
|
|
+ UMSocialPlatformType platformType = UMSocialPlatformType_WechatSession;
|
|
|
+ if([@"WEIXIN" isEqualToString:platform]){
|
|
|
+ platformType = UMSocialPlatformType_WechatSession;
|
|
|
+ }else if([@"WEIXIN_CIRCLE" isEqualToString:platform]){
|
|
|
+ platformType = UMSocialPlatformType_WechatTimeLine;
|
|
|
+ }else if([@"WEIXIN_FAVORITE" isEqualToString:platform]){
|
|
|
+ platformType = UMSocialPlatformType_WechatFavorite;
|
|
|
+ }else if([@"QQ" isEqualToString:platform]){
|
|
|
+ platformType = UMSocialPlatformType_QQ;
|
|
|
+ }else if([@"QZONE" isEqualToString:platform]){
|
|
|
+ platformType = UMSocialPlatformType_Qzone;
|
|
|
+ }else if([@"SINA" isEqualToString:platform]){
|
|
|
+ platformType = UMSocialPlatformType_Sina;
|
|
|
+ }
|
|
|
+ //调用分享接口
|
|
|
+ [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self.viewController completion:^(id data,NSError* error){
|
|
|
+ if(error){
|
|
|
+ NSLog(@"************Share fail with error %@*********",error);
|
|
|
+ }else{
|
|
|
+ NSLog(@"response data is %@",data);
|
|
|
+ }
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
+- (UMShareImageObject*) toImg:(NSString*)imgUrl{
|
|
|
+ UMShareImageObject*shareObject =[[UMShareImageObject alloc] init];
|
|
|
+ NSRegularExpression* regxp = [NSRegularExpression regularExpressionWithPattern:@"^(http|https)$" options:NSRegularExpressionCaseInsensitive error:nil];
|
|
|
+ if ([regxp numberOfMatchesInString:imgUrl options:0 range:NSMakeRange(0, [imgUrl length])]) {
|
|
|
+ [shareObject setShareImage:imgUrl];
|
|
|
+ }else{
|
|
|
+ NSRange range = [imgUrl rangeOfString:@","];
|
|
|
+ NSString* base64 = [imgUrl substringFromIndex:range.location+1];
|
|
|
+ [shareObject setShareImage:[[NSData alloc] initWithBase64EncodedString:base64 options:0]];
|
|
|
+ }
|
|
|
+ return shareObject;
|
|
|
}
|
|
|
@end
|