my front end, recently working on the RN project, needs to use Xiaomi"s message push service, and the code can print out regId and registered deviceToken information. However, the callback miPushReceiveNotification
function is not executed because the corresponding log is not printed. Specific code:
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
-sharpimport "AppDelegate.h"
-sharpimport "MiPushSDK.h"
-sharpimport <React/RCTBundleURLProvider.h>
-sharpimport <React/RCTRootView.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *jsCodeLocation;
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"friday"
initialProperties:nil
launchOptions:launchOptions];
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
NSLog(@"===**&&**====%@", [MiPushSDK getRegId]);
/**
* APNs
*/
[MiPushSDK registerMiPush:self type:0 connect:YES];
// app
NSDictionary* userInfo = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if(userInfo){//
NSString *messageId = [userInfo objectForKey:@"_id_"];
if (messageId!=nil) {
[MiPushSDK openAppNotify:messageId];
}
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"gg" message:[NSString stringWithFormat:@"%@", userInfo] preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *act = [UIAlertAction actionWithTitle:@"" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}];
[alert addAction:act];
}
return YES;
}
- (void)application:(UIApplication *)app
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
// APNS, deviceToken
[MiPushSDK bindDeviceToken:deviceToken];
NSLog(@"------");
NSLog(@" = %@", deviceToken);
}
- (void)application:(UIApplication *)app
didFailToRegisterForRemoteNotificationsWithError:(NSError *)err
{
// APNS
//
NSLog(@"------");
}
- (void)miPushRequestSuccWithSelector:(NSString *)selector data:(NSDictionary *)data
{
//
// regId
NSLog(@"------");
if ([selector isEqualToString:@"bindDeviceToken:"]) {
NSLog(@"regid = %@", data[@"regid"]);
}
}
- (void)miPushRequestErrWithSelector:(NSString *)selector error:(int)error data:(NSDictionary *)data
{
//
NSLog(@"------");
}
- ( void )miPushReceiveNotification:( NSDictionary *)data
{
// APNs
// NSLog(@"msg***= %@", data);
NSLog(@"------");
NSLog(@"what is this = %@", data);
}
- ( void )application:( UIApplication *)application didReceiveRemoteNotification:( NSDictionary *)userInfo
{
[ MiPushSDK handleReceiveRemoteNotification :userInfo];
// miPushReceiveNotification:App
NSString *messageId = [userInfo objectForKey:@"_id_"];
[MiPushSDK openAppNotify:messageId];
NSLog(@"-222-----");
}
// iOS10
//
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
NSDictionary * userInfo = notification.request.content.userInfo;
NSLog(@"iOS10------");
if([notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
[MiPushSDK handleReceiveRemoteNotification:userInfo];
}
// completionHandler(UNNotificationPresentationOptionAlert);
}
//
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
NSDictionary * userInfo = response.notification.request.content.userInfo;
if([response.notification.request.trigger isKindOfClass:[UNPushNotificationTrigger class]]) {
[MiPushSDK handleReceiveRemoteNotification:userInfo];
}
completionHandler();
}
@end
Please take a look at it. Is there a problem?