Apple’s own sharing, image saving authorization and application jump

// NSString *testToShare = @"Shared title";

//                NSURL *urlToShare = [NSURL URLWithString:@"http://www.baidu.com"];

//                UIImage *imageToShare = image;

//                  NSArray *activityItems = @[testToShare,imageToShare,urlToShare];

                

                UIImage *imageToShare = image;

                NSArray *activityItems = @[imageToShare];

                UIActivityViewController *activityVc = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];

                activityVc.excludedActivityTypes = @[UIActivityTypePrint,UIActivityTypeCopyToPasteboard,UIActivityTypeAssignToContact,UIActivityTypeSaveToCameraRoll];

                

                [self presentViewController:activityVc animated:YES completion:nil];

                    activityVc.completionWithItemsHandler = ^(UIActivityType  _Nullable activityType, BOOL completed, NSArray * _Nullable returnedItems, NSError * _Nullable activityError) {

                        if (completed) {

                            NSLog(@"Sharing Successful");

                        }else{

                            NSLog(@"Sharing Cancel");

                        }

                        

                    };

The pop-up box is in English, how to change it to Chinese?

the first method:

Select the project name in project, as shown in the figure below:

Screenshot 2016-10-10 1.45.42 PM.png

Click "+" under Localizations and select Chinese (simplified), as shown in the figure below:

Screenshot 2016-10-10 1.47.42 PM.png

Just click "Done".

The second method:

Open the info.plist file and add the Localizations key-value pair in it, as shown in the figure below. That's it.

Screenshot 2016-10-10 1.50.49 PM.png


2. Save pictures to album and set permissions

if ([PHPhotoLibrary authorizationStatus] == PHAuthorizationStatusAuthorized){//The user has been authorized before

                       //Perform saving image operation

                    UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);

                   }

                else if ([PHPhotoLibrary authorizationStatus] == PHAuthorizationStatusDenied){//The user has denied authorization before

                       UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"Prompt" message:@"You have previously denied access to the photo album, please go to the mobile phone privacy settings" preferredStyle:UIAlertControllerStyleAlert];

                       UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

                           //[self dismissViewControllerAnimated:YES completion:nil];

                           NSURL *url = [NSURL URLWithString:@"App-prefs:root=Photos"];

                           if([[UIApplication sharedApplication] canOpenURL:url]){

                               if([[UIDevice currentDevice].systemVersion doubleValue] >= 10.0) {

                                   [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];

                               }

                               else{

                                   [[UIApplication sharedApplication] openURL:url];

                               }};

                       }];

                       [alertC addAction:sureAction];

                       [self presentViewController:alertC animated:YES completion:nil];

                   }

                   else {//Listen when the pop-up window is authorized

                       [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {

                           if (status == PHAuthorizationStatusAuthorized){//允许

                              //Perform saving image operation

                               UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);

                           }

                           else {//Reject

                               [self dismissViewControllerAnimated:YES completion:nil];

                           }

                       }];

                   }

How to jump to the system settings interface of APP developed for IOS

In IOS development, we sometimes encounter such a requirement. When the APP needs to obtain permission to use the camera/album and other systems, but the user does not authorize it for the first time, when the user enters again, we need to prompt the user to open it. permissions, and jump directly to the system settings interface for authorization.

There are 2 methods 

1. Add the following code directly to the click event method of the jump button

NSURL*url = [NSURLURLWithString:UIApplicationOpenSettingsURLString];if([[UIApplicationsharedApplication] canOpenURL:url]) {    [[UIApplicationsharedApplication] openURL:url];}

This situation is usually caused by certain operations being performed in the wrong thread. The solution is to use a delay mechanism.

dispatch_after(0.2, dispatch_get_main_queue(), ^{NSURL*url = [NSURLURLWithString:UIApplicationOpenSettingsURLString];if([[UIApplicationsharedApplication] canOpenURL:url]) {        [[UIApplicationsharedApplication] openURL:url];    }});

two, 

1. First add the following code to the click event method of the jump button. There will be changes after iOS 10, so a judgment must be added.

NSURL*url = [NSURLURLWithString:@"App-Prefs:root=WIFI"];if([[UIApplicationsharedApplication] canOpenURL:url]){if([[UIDevice currentDevice].systemVersiondoubleValue] >=10.0) {        [[UIApplicationsharedApplication] openURL:url options:@{} completionHandler:nil];    }else{        [[UIApplicationsharedApplication] openURL:url];    }}

2. Then add URL types to the info.plist in the project and set one URL Schemes to prefs, as shown below:

Note: In the String field, @"App-Prefs:root=WIFI", versions below iOS10 do not need to add "App-", but versions above iOS10 must add it, otherwise the jump will not work.

What is demonstrated here is to jump to the WIFI interface of the system. Of course, you can also modify the string and jump to the corresponding setting interface.

@"App-prefs:root=WIFI" //Turn on WiFi

@"App-prefs:root=Bluetooth" //Open the Bluetooth settings page

@"App-prefs:root=AIRPLANE_MODE" //Turn on airplane mode

@"App-prefs:root=MOBILE_DATA_SETTINGS_ID" //Cellular mobile network

@"App-prefs:root=INTERNET_TETHERING" //Personal hotspot

@"App-prefs:root=NOTIFICATIONS_ID" //Notification settings

@"App-prefs:root=General" //General

@"App-prefs:root=General&path=About" //General-About this machine     

@"App-prefs:root=DISPLAY&BRIGHTNESS" //Display and brightness

@"App-prefs:root=Wallpaper" //Wallpaper

@"App-prefs:root=Sounds" //Sounds

@"App-prefs:root=Privacy" //Privacy

@"App-prefs:root=STORE" //Storage

@"App-prefs:root=NOTES" //Notes

@"App-prefs:root=SAFARI" //Safari

@"App-prefs:root=MUSIC" //Music

@"App-prefs:root=Photos" //Photos and Camera

@"App-prefs:root=CASTLE" //iCloud

@"App-prefs:root=FACETIME" //FaceTime

@"App-prefs:root=LOCATION_SERVICES" //Location services

@"App-prefs:root=Phone" //Phone

//General common fields

@"prefs:root=General&path=About" //About this machine

@"prefs:root=General&path=SOFTWARE_UPDATE_LINK" //Software update

@"prefs:root=General&path=DATE_AND_TIME" //Date and time

@"prefs:root=General&path=ACCESSIBILITY" //Auxiliary functions

@"prefs:root=General&path=Keyboard" //Keyboard

@"prefs:root=General&path=VPN" //VPN settings

@"prefs:root=General&path=AUTOLOCK" //Automatically lock the screen

@"prefs:root=General&path=INTERNATIONAL" //Language and region

@"prefs:root=General&path=ManagedConfigurationList" //Description file

//Common fields under privacy

@"prefs:root=Privacy&path=CAMERA" //Set camera permissions

@"prefs:root=Privacy&path=PHOTOS" //Set photo usage permissions

oot=Privacy&path=PHOTOS"//Set photo usage permissions



Author: pentakill
Link: https://www.jianshu.com/p/9cb4c794b9f7
Source: Jianshu
Copyright belongs to the author. For commercial reprinting, please contact the author for authorization. For non-commercial reprinting, please indicate the source.

Guess you like

Origin blog.csdn.net/u013712343/article/details/131591572