| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 | <!DOCTYPE HTML><html>	<head>		<meta charset="utf-8"/>		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>		<meta name="HandheldFriendly" content="true"/>		<meta name="MobileOptimized" content="320"/>		<title>Hello H5+</title>		<script type="text/javascript" src="../js/common.js"></script>		<script type="text/javascript">/*	NSNotificationCenter *nc = nil;// 游戏玩家登录状态监听函数- (void)authenticationChanged:(NSNotification*)notification{    // 获取游戏玩家共享实例对象    GKLocalPlayer *player = notification.object;    if ( player.isAuthenticated ) {        // 玩家已登录认证,获取玩家信息        [self playerInformation:player];    } else {        // 玩家未登录认证,提示用户登录        NSLog(@"请登录!");    }    // 释放使用的对象    [player release];}// 获取游戏玩家状态信息- (void)playerInformation:(GKPlayer *)player{    // 获取游戏玩家的名称    NSLog(@"Name: %@",player.displayName);}// 登录到游戏中心- (void)loginGamecenter{    // 获取游戏玩家共享实例对象    GKLocalPlayer *localplayer = [GKLocalPlayer localPlayer];    // 判断游戏玩家是否已经登录认证    if ( localplayer.isAuthenticated ) {        // 玩家已登录认证,获取玩家信息        [self playerInformation:localplayer];    } else {	    // 监听用户登录状态变更事件	    if(!nc){		    nc = [NSNotificationCenter defaultCenter];		    [nc addObserver:self		           selector:@selector(authenticationChanged)		               name:@"GKPlayerAuthenticationDidChangeNotificationName"		             object:nil];		}        // 玩家未登录认证,发起认证请求        [localplayer authenticateWithCompletionHandler:nil];        NSLog(@"登录中...");    }	// 释放使用的对象    [localplayer release];}// 停止监听登录游戏状态变化- (void)logoutGamecenter{    // 取消监听用户登录状态变化    if(nc){	    [nc removeObserver:self	                  name:@"GKPlayerAuthenticationDidChangeNotificationName"	                object:nil];	}}*/// H5 plus事件处理var GKLocalPlayer=null,NSNotificationCenter=null;var nc=null,delegate=null;function plusReady(){	plus.webview.currentWebview().setStyle({popGesture:"none"});	if ( plus.os.name == "iOS" ) {		GKLocalPlayer  = plus.ios.importClass("GKLocalPlayer");		NSNotificationCenter = plus.ios.importClass("NSNotificationCenter");		longinGamecenter();	} else {		eStart.innerText = "欢迎您";		bLogin = true;		setTimeout( function(){			plus.nativeUI.toast( "此平台不支持Game Center功能!" );		}, 500 );	}}if(window.plus){	plusReady();}else{	document.addEventListener("plusready",plusReady,false);}// DOMContentLoaded事件处理var eStart=null,bLogin=false;document.addEventListener("DOMContentLoaded",function(){	eStart = document.getElementById( "start" );},false);// 游戏玩家登录状态监听函数function authenticationChanged( notification ){	// 获取游戏玩家共享实例对象	var player = notification.plusGetAttribute("object");	if ( player.plusGetAttribute("isAuthenticated") ) {		// 玩家已登录认证,获取玩家信息		playerInformation(player);		bLogin = true;	} else {		// 玩家未登录认证,提示用户登录		setTimeout(function(){			eStart.innerText = "请登录";	        bLogin = false;		},500);	}	// 释放使用的对象//	plus.ios.deleteObject(player);}// 获取游戏玩家状态信息function playerInformation( player ){	var name = player.plusGetAttribute("displayName");	eStart.innerText = name+" 已登录!";}// 登录到游戏中心function longinGamecenter(){	if ( bLogin ){		return;	}    // 获取游戏玩家共享实例对象    var localplayer = GKLocalPlayer.localPlayer();    // 判断游戏玩家是否已经登录认证    if ( localplayer.plusGetAttribute("isAuthenticated") ) {        // 玩家已登录认证,获取玩家信息        playerInformation( localplayer );        bLogin = true;    } else {        eStart.innerText = "登录中...";		// 监听用户登录状态变更事件	    if(!nc){	    	nc = NSNotificationCenter.defaultCenter();	    	delegate||(delegate=plus.ios.implements("NSObject",{"authenticationChanged:":authenticationChanged}));	    	nc.addObserverselectornameobject(delegate,		    	plus.ios.newObject("@selector","authenticationChanged:"),		    	"GKPlayerAuthenticationDidChangeNotificationName",		    	null);	    }        // 玩家未登录认证,发起认证请求        localplayer.authenticateWithCompletionHandler(null);    }    // 释放使用的对象	plus.ios.deleteObject(localplayer);}// 停止监听登录游戏状态变化function stopGamecenterObserver(){    // 取消监听用户登录状态变化    nc&&nc.removeObservernameobject(delegate,"GKPlayerAuthenticationDidChangeNotificationName",null);    plus.ios.deleteObject(nc);nc = null;    plus.ios.deleteObject(delegate);delegate = null;}		</script>		<style type="text/css">* {	-webkit-user-select: none;	-ms-touch-select: none;}html {	width: 100%;	height: 100%;}body {	margin: 0;	padding: 0;	width: 100%;	height: 100%;	text-align: center;	-webkit-touch-callout:none;	-webkit-tap-highlight-color:rgba(0,0,0,0);}header {	height: 44px;	font-size: 22px;	line-height: 44px;	font-weight: bold;	color: #000000;}.game {	position:fixed;	top:44px;	width:100%;	bottom: 60px;	background: no-repeat center center url(../img/5.jpg);}.button {	font-size: 18px;	font-weight: normal;	text-decoration: none;	display: block;	text-align: center;	color: #fff;	background-color: #FFCC33;	border: 1px solid #ECB100;	padding: .5em 0em;	margin: .5em .7em;	-webkit-border-radius: 5px;	border-radius: 5px;}.button:active {	outline: 0;	-webkit-box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125);	box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125);}.start {	width: 50%;	font-size: 18px;	font-weight: normal;	text-decoration: none;	display: block;	text-align: center;	color: #666;	background-color: #EBEBEB;	border: 1px solid #E0E0E0;	padding: .5em 0em;	margin: .5em auto;	-webkit-border-radius: 5px;	border-radius: 5px;}		</style>		<style type="text/css" media="screen and (min-aspect-ratio: 1/1)">.autobg {	background-size: auto 100%;}		</style>		<style type="text/css" media="screen and (max-aspect-ratio: 1/1)">.autobg {	background-size: 100% auto;}		</style>	</head>	<body style="background:#CCCCCC;">		<header id=header>五子棋</header>		<div class="game autobg">		</div>		<div style="position:fixed;bottom:0;width:100%;height:60px;text-align:center;">			<div class="button" onclick="try{stopGamecenterObserver();}catch(e){}back();">退出</div>		</div>		<div style="position:fixed;top:30%;width:100%;text-align:center;">			<div id="start" class="start" onclick="longinGamecenter();">登录中...</div>		</div>	</body></html>
 |