Пример #1
0
        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);
        }
Пример #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));
        }