ios.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // pages/ios/ios.js
  2. const { miniAppPluginId } = require('../../constant');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. myPlugin: undefined,
  9. quickStartContents: [
  10. '在「设置」->「安全设置」中手动开启多端插件服务端口',
  11. '在「工具栏」->「运行设备」中选择 iOS 点击「运行」,快速准备运行环境',
  12. '在打开的 Xcode 中点击「播放」运行原生工程',
  13. '保持开发者工具开启,修改小程序代码和原生代码仅需在 Xcode 中点击「播放」查看效果',
  14. ]
  15. },
  16. onLoadPlugin() {
  17. wx.miniapp.loadNativePlugin({
  18. pluginId: miniAppPluginId,
  19. success: (plugin) => {
  20. console.log('load plugin success', plugin)
  21. this.setData({
  22. myPlugin: plugin
  23. })
  24. },
  25. fail: (e) => {
  26. console.log('load plugin fail', e)
  27. }
  28. })
  29. },
  30. onUsePlugin() {
  31. const { myPlugin } = this.data
  32. if (!myPlugin) {
  33. console.log('plugin is undefined')
  34. return
  35. }
  36. const ret = myPlugin.mySyncFunc({ a: 'hello', b: [1,2] })
  37. console.log('mySyncFunc ret:', ret)
  38. myPlugin.myAsyncFuncwithCallback({ a: 'hello', b: [1,2] }, (ret) => {
  39. console.log('myAsyncFuncwithCallback ret:', ret)
  40. })
  41. },
  42. copyLink() {
  43. wx.setClipboardData({
  44. data: 'https://dev.weixin.qq.com/docs/framework/dev/plugin/iosPlugin.html',
  45. })
  46. }
  47. })