public void Register(AppDelegate app, NSDictionary options)
        {
            //注册apns远程推送
            string advertisingId = AdSupport.ASIdentifierManager.SharedManager.AdvertisingIdentifier.AsString();

            this.entity       = new JPushRegisterEntity();
            this.entity.Types = 1 | 2 | 3;//entity.Types = (nint)(JPAuthorizationOptions.Alert) | JPAuthorizationOptions.Badge | JPAuthorizationOptions.Sound;
            JPUSHService.RegisterForRemoteNotificationConfig(entity, this);
            JPUSHService.SetupWithOption(options, JPushAppKey, Channel, true, advertisingId);
            JPUSHService.RegistrationIDCompletionHandler(app.GetRegistrationID);
        }
Exemple #2
0
        //
        // This method is invoked when the application has loaded and is ready to run. In this
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();
            // Override point for customization after application launch.
            // If not required for your application you can safely delete this method

            JPUSHRegisterEntity entity = new JPUSHRegisterEntity();

            if (UIDevice.CurrentDevice.CheckSystemVersion(12, 0))
            {
                entity.Types = (nint)((long)JPAuthorizationOptions.Alert | (long)JPAuthorizationOptions.Badge | (long)JPAuthorizationOptions.Sound | (long)JPAuthorizationOptions.ProvidesAppNotificationSettings);
            }
            else
            {
                entity.Types = (nint)((long)JPAuthorizationOptions.Alert | (long)JPAuthorizationOptions.Badge | (long)JPAuthorizationOptions.Sound);
            }

            if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
            {
                // 可以添加自定义categories
                //if(UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
                //{
                //      NSSet<UNNotificationCategory *> *categories;
                //    NSSet categories = null;
                //   entity.Categories = categories;
                //}
                //else
                //{
                //      NSSet<UIUserNotificationCategory *> *categories;
                //   NSSet categories = null;
                //    entity.Categories = categories;
                //}
            }

            JPUSHService.RegisterForRemoteNotificationConfig(entity, new PUSHRegisterDelegate());
            JPUSHService.SetupWithOption(options, "3e56b44642dba83d39839e88", "Channel", true);

            JPUSHService.RegistrationIDCompletionHandler((resCode, registrationID) =>
            {
                if (resCode == 0)
                {
                    System.Diagnostics.Debug.WriteLine("registrationID获取成功:" + registrationID);
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("registrationID获取失败:" + registrationID);
                }
            });

            LoadApplication(new App());

            return(base.FinishedLaunching(app, options));
        }
Exemple #3
0
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            // Override point for customization after application launch.
            // If not required for your application you can safely delete this method
            Window = new UIWindow(UIScreen.MainScreen.Bounds);
            Window.BackgroundColor = UIColor.GroupTableViewBackgroundColor;

            #region 极光推送注册
            MsgBoxHelper.Initialize(this);
            if (float.Parse(UIDevice.CurrentDevice.SystemVersion.Split('.')[0]) >= 10.0)
            {
                UNUserNotificationCenter center = UNUserNotificationCenter.Current;
                center.RequestAuthorization((UNAuthorizationOptions.CarPlay | UNAuthorizationOptions.Alert | UNAuthorizationOptions.Sound | UNAuthorizationOptions.Badge), (bool arg1, NSError arg2) =>
                {
                    if (arg1)
                    {
                        Console.WriteLine("ios 10 request notification success");
                    }
                    else
                    {
                        Console.WriteLine("IOS 10 request notification failed");
                    }
                });
            }
            else if (float.Parse(UIDevice.CurrentDevice.SystemVersion.Split('.')[0]) >= 8.0)
            {
                UIUserNotificationSettings notiSettings = UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Badge | UIUserNotificationType.Sound | UIUserNotificationType.Alert, null);
                UIApplication.SharedApplication.RegisterUserNotificationSettings(notiSettings);
            }
            else
            {
                UIRemoteNotificationType myTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Sound | UIRemoteNotificationType.Badge;
                UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(myTypes);
            }

            /*
             * JPUSHService.SetupWithOption(launchOptions, "466439cd8279089311ead639", "Publish channel", false);
             * 将上面代码中的应用程序码换成你在极光服务器上注册的应用码,通过极光服务器发送推送消息,在真机上测试即可收到。
             */
            JPUSHService.SetupWithOption(launchOptions, "466439cd8279089311ead639", "Publish channel", false);
            JPUSHService.SetDebugMode();
            UIApplication.SharedApplication.RegisterForRemoteNotifications();
            //JPUSHService.RegistrationIDCompletionHandler((int arg1, NSString arg2) =>
            //{
            //	if (arg1 == 0)
            //		Console.WriteLine(arg2);
            //});
            if (launchOptions != null)
            {
                NSDictionary remoteNotification = (NSDictionary)(launchOptions.ObjectForKey(UIApplication.LaunchOptionsRemoteNotificationKey));
                if (remoteNotification != null)
                {
                    Console.WriteLine(remoteNotification);
                    this.goToMessageViewControllerWith(remoteNotification);
                }
            }
            #endregion
            Window.RootViewController = new UINavigationController(new ViewController());
            // make the window visible
            Window.MakeKeyAndVisible();

            return(true);
        }