Commit 84d53a12 authored by Nature's avatar Nature

修复iphone 7及以后的手机问题

parents
PrivacyScreenPlugin
==================
Both iOS (as of iOS 7) and Android have app switchers that display a screenshot of your app.
This is a lovely feature for most apps, but if your app displays sensitive information this is a possible privacy risk.
This plugin flags your app so that it doesn't show your users' sensitive data in the task switcher. It sets the [FLAG_SECURE](http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html#FLAG_SECURE) flag in Android (which also prevents manual screenshots from being taken) and hides the window in iOS.
On iOS this plugin will try to show your splashscreen in the app switcher. It will search for splashscreens prefixed by `Default` or the value of the key `UILaunchImageFile` in your .plist file.
If it fails to find a splashscreen for a specific device or orientation (portrait or landscape), a black screen is shown instead.
Installation
------------
For Cordova 3.x.x:
1. To add this plugin just type: `cordova plugin add cordova-plugin-privacyscreen` or `phonegap local plugin add cordova-plugin-privacyscreen`
2. To remove this plugin type: `cordova plugin remove cordova-plugin-privacyscreen` or `phonegap local plugin remove cordova-plugin-privacyscreen`
Usage:
------
This plugin exposes no interface, it simply sets your app to be private. You don't need to do anything except install the plugin.
Test this plugin on a real device because the iOS simulator (7.1 at least) does a poor job hiding your app.
## License
The MIT License
Copyright (c) 2014 Tommy-Carlos Williams (http://github.com/devgeeks)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
{
"name": "cordova-plugin-privacyscreen",
"version": "0.2.0",
"description": "Secures your app from displaying a screenshot in task switchers under Android and iOS. Keeps sensitive information private.",
"cordova": {
"id": "cordova-plugin-privacyscreen",
"platforms": [
"android",
"ios"
]
},
"repository": {
"type": "git",
"url": "git+https://github.com/devgeeks/PrivacyScreenPlugin.git"
},
"keywords": [
"privacy",
"cordova",
"ecosystem:cordova",
"cordova-android",
"cordova-ios"
],
"author": "Tommy-Carlos Willaims <tommy@devgeeks.org>",
"license": "MIT",
"bugs": {
"url": "https://github.com/devgeeks/PrivacyScreenPlugin/issues"
},
"homepage": "https://github.com/devgeeks/PrivacyScreenPlugin#readme"
}
<?xml version="1.0" encoding="utf-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="cordova-plugin-privacyscreen" version="0.3.0">
<name>PrivacyScreenPlugin</name>
<description>Secures your app from displaying a screenshot in task switchers under Android and iOS. Keeps sensitive information private.</description>
<license>MIT</license>
<platform name="android">
<config-file parent="/*" target="res/xml/config.xml">
<feature name="PrivacyScreenPlugin">
<param name="android-package" value="org.devgeeks.privacyscreen.PrivacyScreenPlugin"/>
<param name="onload" value="true" />
</feature>
</config-file>
<source-file src="src/android/PrivacyScreenPlugin.java" target-dir="src/org/devgeeks/privacyscreen"/>
</platform>
<platform name="ios">
<config-file parent="/*" target="config.xml">
<feature name="PrivacyScreenPlugin">
<param name="ios-package" value="PrivacyScreenPlugin"/>
<param name="onload" value="true" />
</feature>
</config-file>
<source-file src="src/ios/PrivacyScreenPlugin.h"/>
<source-file src="src/ios/PrivacyScreenPlugin.m"/>
</platform>
</plugin>
/**
* PrivacyScreenPlugin.java Cordova Plugin Implementation
* Created by Tommy-Carlos Williams on 18/07/14.
* Copyright (c) 2014 Tommy-Carlos Williams. All rights reserved.
* MIT Licensed
*/
package org.devgeeks.privacyscreen;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaWebView;
import android.app.Activity;
import android.view.Window;
import android.view.WindowManager;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.Context;
import android.os.Bundle;
/**
* This class sets the FLAG_SECURE flag on the window to make the app
* private when shown in the task switcher
*/
public class PrivacyScreenPlugin extends CordovaPlugin {
@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
Activity activity = this.cordova.getActivity();
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
}
/**
* PrivacyScreenPlugin.h
* Created by Tommy-Carlos Williams on 18/07/2014
* Copyright (c) 2014 Tommy-Carlos Williams. All rights reserved.
* MIT Licensed
*/
#import <Cordova/CDV.h>
#import <Cordova/CDVPlugin.h>
typedef struct {
BOOL iPhone;
BOOL iPad;
BOOL iPhone4;
BOOL iPhone5;
BOOL iPhone6;
BOOL iPhone6Plus;
BOOL retina;
BOOL iPhoneX;
} CDV_iOSDevice;
@interface PrivacyScreenPlugin : CDVPlugin
@end
/**
* PrivacyScreenPlugin.m
* Created by Tommy-Carlos Williams on 18/07/2014
* Copyright (c) 2014 Tommy-Carlos Williams. All rights reserved.
* MIT Licensed
*/
#import "PrivacyScreenPlugin.h"
UIImageView *imageView;
@implementation PrivacyScreenPlugin
- (void)pluginInitialize
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppDidBecomeActive:)
name:UIApplicationDidBecomeActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppWillResignActive:)
name:UIApplicationWillResignActiveNotification object:nil];
}
- (void)onAppDidBecomeActive:(UIApplication *)application
{
if (imageView == NULL) {
self.viewController.view.window.hidden = NO;
} else {
[imageView removeFromSuperview];
}
}
- (void)onAppWillResignActive:(UIApplication *)application
{
CDVViewController *vc = (CDVViewController*)self.viewController;
NSString *imgName = [self getImageName:self.viewController.interfaceOrientation delegate:(id<CDVScreenOrientationDelegate>)vc device:[self getCurrentDevice]];
UIImage *splash = [UIImage imageNamed:imgName];
if (splash == NULL) {
self.viewController.view.window.hidden = YES;
} else {
imageView = [[UIImageView alloc]initWithFrame:[self.viewController.view bounds]];
[imageView setImage:splash];
[self.viewController.view addSubview:imageView];
}
}
- (BOOL) isUsingCDVLaunchScreen {
NSString* launchStoryboardName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UILaunchStoryboardName"];
if (launchStoryboardName) {
return ([launchStoryboardName isEqualToString:@"CDVLaunchScreen"]);
} else {
return NO;
}
}
// Code below borrowed from the CDV splashscreen plugin @ https://github.com/apache/cordova-plugin-splashscreen
// Made some adjustments though, becuase landscape splashscreens are not available for iphone < 6 plus
- (CDV_iOSDevice) getCurrentDevice
{
CDV_iOSDevice device;
UIScreen* mainScreen = [UIScreen mainScreen];
CGFloat mainScreenHeight = mainScreen.bounds.size.height;
CGFloat mainScreenWidth = mainScreen.bounds.size.width;
int limit = MAX(mainScreenHeight,mainScreenWidth);
device.iPad = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad);
device.iPhone = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone);
device.retina = ([mainScreen scale] == 2.0);
device.iPhone4 = (device.iPhone && limit == 480.0);
device.iPhone5 = (device.iPhone && limit == 568.0);
// note these below is not a true device detect, for example if you are on an
// iPhone 6/6+ but the app is scaled it will prob set iPhone5 as true, but
// this is appropriate for detecting the runtime screen environment
device.iPhone6 = (device.iPhone && limit == 667.0);
device.iPhone6Plus = (device.iPhone && limit == 736.0);
device.iPhoneX = (device.iPhone && limit == 812.0);
return device;
}
- (NSString*)getImageName:(UIInterfaceOrientation)currentOrientation delegate:(id<CDVScreenOrientationDelegate>)orientationDelegate device:(CDV_iOSDevice)device
{
// Use UILaunchImageFile if specified in plist. Otherwise, use Default.
NSString* imageName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UILaunchImageFile"];
// detect if we are using CB-9762 Launch Storyboard; if so, return the associated image instead
if ([self isUsingCDVLaunchScreen]) {
imageName = @"LaunchStoryboard";
return imageName;
}
NSUInteger supportedOrientations = [orientationDelegate supportedInterfaceOrientations];
// Checks to see if the developer has locked the orientation to use only one of Portrait or Landscape
BOOL supportsLandscape = (supportedOrientations & UIInterfaceOrientationMaskLandscape);
BOOL supportsPortrait = (supportedOrientations & UIInterfaceOrientationMaskPortrait || supportedOrientations & UIInterfaceOrientationMaskPortraitUpsideDown);
// this means there are no mixed orientations in there
BOOL isOrientationLocked = !(supportsPortrait && supportsLandscape);
if (imageName)
{
imageName = [imageName stringByDeletingPathExtension];
}
else
{
imageName = @"Default";
}
// Add Asset Catalog specific prefixes
if ([imageName isEqualToString:@"LaunchImage"])
{
if (device.iPhone4 || device.iPhone5 || device.iPad) {
imageName = [imageName stringByAppendingString:@"-700"];
} else if(device.iPhone6) {
imageName = [imageName stringByAppendingString:@"-800"];
} else if(device.iPhone6Plus || device.iPhoneX ) {
if(device.iPhone6Plus) {
imageName = [imageName stringByAppendingString:@"-800"];
} else {
imageName = [imageName stringByAppendingString:@"-1100"];
}
if (currentOrientation == UIInterfaceOrientationPortrait || currentOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
imageName = [imageName stringByAppendingString:@"-Portrait"];
}
}
}
if (device.iPhone5)
{ // does not support landscape
imageName = [imageName stringByAppendingString:@"-568h"];
}
else if (device.iPhone6)
{ // does not support landscape
imageName = [imageName stringByAppendingString:@"-667h"];
}
else if (device.iPhone6Plus || device.iPhoneX)
{ // supports landscape
if (isOrientationLocked)
{
imageName = [imageName stringByAppendingString:(supportsLandscape ? @"-Landscape" : @"")];
}
else
{
switch (currentOrientation)
{
case UIInterfaceOrientationLandscapeLeft:
case UIInterfaceOrientationLandscapeRight:
imageName = [imageName stringByAppendingString:@"-Landscape"];
break;
default:
break;
}
}
if (device.iPhoneX) {
imageName = [imageName stringByAppendingString:@"-2436h"];
} else {
imageName = [imageName stringByAppendingString:@"-736h"];
}
}
else if (device.iPad)
{ // supports landscape
if (isOrientationLocked)
{
imageName = [imageName stringByAppendingString:(supportsLandscape ? @"-Landscape" : @"-Portrait")];
}
else
{
switch (currentOrientation)
{
case UIInterfaceOrientationLandscapeLeft:
case UIInterfaceOrientationLandscapeRight:
imageName = [imageName stringByAppendingString:@"-Landscape"];
break;
case UIInterfaceOrientationPortrait:
case UIInterfaceOrientationPortraitUpsideDown:
default:
imageName = [imageName stringByAppendingString:@"-Portrait"];
break;
}
}
}
return imageName;
}
@end
//var exec = require('cordova/exec');
/**
* Not sure this will even have a JS API
*/
//exports.activate = function(arg, success, error) {
//exec(success, error, "PrivacyScreenPlugin", "activate", [arg]);
//};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment