Javascript 使用Phonegap复制到剪贴板iOS
我正在使用cordova 2.5.0。我正在尝试在ios中将文本复制到剪贴板 我遇到了这个插件 但这个似乎有点过时了 我已经将ClipboardPlugin.h和ClipboardPlugin.m放在Plugins文件夹中,并根据最新版本修改了类 在ClipboardPlugin.h中 在ClipboardPlugin.m中 和config.xml 但是当尝试使用 window.plugins.clipboardPlugin.setTextomg\n此规则Javascript 使用Phonegap复制到剪贴板iOS,javascript,ios,objective-c,cordova,phonegap-plugins,Javascript,Ios,Objective C,Cordova,Phonegap Plugins,我正在使用cordova 2.5.0。我正在尝试在ios中将文本复制到剪贴板 我遇到了这个插件 但这个似乎有点过时了 我已经将ClipboardPlugin.h和ClipboardPlugin.m放在Plugins文件夹中,并根据最新版本修改了类 在ClipboardPlugin.h中 在ClipboardPlugin.m中 和config.xml 但是当尝试使用 window.plugins.clipboardPlugin.setTextomg\n此规则 事情不顺利。如何让这个插件运行。谢谢
事情不顺利。如何让这个插件运行。谢谢 您的要求是在iOS中将文本复制到剪贴板,请使用以下代码:
[UIPasteboard generalPasteboard].string = @"text you want to copy";
或者使用UIPasteboard类来完成您的需求。OP可能希望通过PhoneGapp HTML5应用程序中的JavaScript来完成。我也想这么做
//
// ClipboardPlugin.m
// Clipboard plugin for PhoneGap
//
// Copyright 2010 Michel Weimerskirch.
//
#import <Foundation/Foundation.h>
#import <Cordova/CDVPlugin.h>
#import "ClipboardPlugin.h"
@implementation ClipboardPlugin
-(void)setText:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options {
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSString *text = [arguments objectAtIndex:0];
[pasteboard setValue:text forPasteboardType:@"public.text"];
}
-(void)getText:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options {
NSString* callbackID = [arguments pop];
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSString *text = [pasteboard valueForPasteboardType:@"public.text"];
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:text];
[self writeJavascript: [pluginResult toSuccessCallbackString:callbackID]];
}
@end
<?xml version="1.0" encoding="UTF-8"?>
<!--
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
-->
<widget>
<preference name="KeyboardDisplayRequiresUserAction" value="true" />
<preference name="SuppressesIncrementalRendering" value="false" />
<preference name="UIWebViewBounce" value="true" />
<preference name="TopActivityIndicator" value="gray" />
<preference name="EnableLocation" value="false" />
<preference name="EnableViewportScale" value="false" />
<preference name="AutoHideSplashScreen" value="true" />
<preference name="ShowSplashScreenSpinner" value="true" />
<preference name="FadeSplashScreen" value="true" />
<preference name="FadeSplashScreenDuration" value=".25" />
<preference name="MediaPlaybackRequiresUserAction" value="false" />
<preference name="AllowInlineMediaPlayback" value="false" />
<preference name="BackupWebStorage" value="cloud" />
<content src="initScreen.html" />
<plugins>
<plugin name="Device" value="CDVDevice" />
<plugin name="Logger" value="CDVLogger" />
<plugin name="Compass" value="CDVLocation" />
<plugin name="Accelerometer" value="CDVAccelerometer" />
<plugin name="Camera" value="CDVCamera" />
<plugin name="NetworkStatus" value="CDVConnection" />
<plugin name="Contacts" value="CDVContacts" />
<plugin name="Debug Console" value="CDVDebugConsole" />
<plugin name="Echo" value="CDVEcho" />
<plugin name="File" value="CDVFile" />
<plugin name="FileTransfer" value="CDVFileTransfer" />
<plugin name="Geolocation" value="CDVLocation" />
<plugin name="Notification" value="CDVNotification" />
<plugin name="Media" value="CDVSound" />
<plugin name="Capture" value="CDVCapture" />
<plugin name="SplashScreen" value="CDVSplashScreen" />
<plugin name="Battery" value="CDVBattery" />
<plugin name="Globalization" value="CDVGlobalization" />
<plugin name="InAppBrowser" value="CDVInAppBrowser" />
<plugin name="ClipboardPlugin" value="ClipboardPlugin" />
</plugins>
<access origin="*" />
</widget>
[UIPasteboard generalPasteboard].string = @"text you want to copy";