Forum Xamarin.iOS


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.


alipishkarialipishkari USMember ✭✭

Hi, I want to make an screanshot in IOS. not from my app,
I want to minimize my app and then make an screanshot.
Please help me.



  • LucasZhangLucasZhang Member, Xamarin Team Xamurai

    We could not capture the screenshot of HomePage in code manually because of apple policy . But we could get the image when user click the lock button and volume + button .

    in AppDelegate

    Firstly, you need to add the permission string in the info.plist:

    <string> photos description. </string>

    Then request the dynamic authorization in the method FinishedLaunching like:

    PHPhotoLibrary.RequestAuthorization((status) =>
       switch (status)
           case PHAuthorizationStatus.Authorized:
                   Debug.WriteLine(“Authorized to access”);
           case PHAuthorizationStatus.Denied: case PHAuthorizationStatus.Restricted:
                   Debug.WriteLine(“Not allowed”);
                   Debug.WriteLine(“Not determined”);

    Add the notification in the method FinishedLaunching so that the app will get the notification when user capture the screen shot .

    using ObjCRuntime;
    using AssetsLibrary;
    using Photos;
     NSNotificationCenter.DefaultCenter.AddObserver(this,new Selector("IsScreenShot:"),UIApplication.UserDidTakeScreenshotNotification,null);
    NSNotificationCenter.DefaultCenter.AddObserver(this, new Selector("GetScreenShot:"), UIApplication.UserDidTakeScreenshotNotification, null);
            bool isScreenShot;  
            void IsScreenShot(NSNotification notification)
                ALAuthorizationStatus kStatus = ALAssetsLibrary.AuthorizationStatus;
                if (kStatus == ALAuthorizationStatus.Authorized)
                    isScreenShot = true;
            //get screenshot (the first photo in album)
            void GetScreenShot(NSNotification notification)
                    PHImageRequestOptions options = new PHImageRequestOptions();
                    options.ResizeMode = PHImageRequestOptionsResizeMode.Fast;
                    options.DeliveryMode = PHImageRequestOptionsDeliveryMode.FastFormat;
                    options.Synchronous = true;
                    var assets = PHAsset.FetchAssets(PHAssetMediaType.Image, null);
                    PHImageManager manager = new PHImageManager();
                    var LastAsset = assets[0] as PHAsset;
                    manager.RequestImageForAsset(LastAsset, PHImageManager.MaximumSize, PHImageContentMode.Default, options,
                                                   (image, info) =>
                                                         //image is the screen shot , do something you want 
                isScreenShot = false;
Sign In or Register to comment.