프로젝트

일반

사용자정보

Cordova-plugin-openwith-ios » 이력 » 버전 1

류창균, 2022/11/25 22:03

1 1 류창균
# Cordova-plugin-openwith-ios
2
3
4
- Cordova create
5
6
```
7
> cordova create sharetest com.test.sharetest ShareTest
8
Creating a new cordova project.
9
```
10
11
```
12
> cd sharetest
13
```
14
15
- Platform add
16
17
```
18
> cordova platform add ios
19
Using cordova-fetch for cordova-ios@^6.2.0
20
Adding ios project...
21
Creating Cordova project for the iOS platform:
22
	Path: platforms/ios
23
	Package: com.test.sharetest
24
	Name: ShareTest
25
iOS project created with cordova-ios@6.2.0
26
```
27
28
- Plugin add
29
30
```
31
> cordova plugin add cordova-plugin-openwith-ios --variable IOS_URL_SCHEME=openwith
32
Installing "cordova-plugin-openwith-ios" for ios
33
Installing "cordova-plugin-openwith-ios" dependencies
34
Copying "cordova-plugin-openwith-ios/ShareExtension" to ios...
35
Adding target "cordova-plugin-openwith-ios/ShareExtension" to XCode project
36
  - Folder containing your iOS project: /Users/ryu/work/travelcoop/sharetest/platforms/ios/
37
    Parsing existing project at location: /Users/ryu/work/travelcoop/sharetest/platforms/ios/ShareTest.xcodeproj/project.pbxproj...
38
    ShareExtension group already exists.
39
Added ShareExtension to XCode project
40
Adding cordova-plugin-openwith-ios to package.json
41
```
42
43
```
44
> cordova prepare
45
~~~
46
47
- Open xcode
48
49
```
50
> open platforms/ios/ShareTest.xcworkspace
51
```
52
53
- Xcode > Signing & Capabilities > Add "App Group"
54
55
![](Screen Shot 1.png)
56
57
![](Screen Shot 2.png)
58
59
![](Screen Shot 6.png)
60
61
![](Screen Shot 3.png)
62
63
![](Screen Shot 4.png)
64
65
- Select team
66
67
![](Screen Shot 5.png)
68
69
- Codova run 
70
71
```
72
> cordova run ios
73
```
74
75
- Simualtor
76
77
![](Simulator Screen Shot - iPhone 14 Pro Max 1.png)
78
79
- Edit test code (./www/js/index.js) 
80
81
``` javascript
82
  // Increase verbosity if you need more logs
83
  //cordova.openwith.setVerbosity(cordova.openwith.DEBUG);
84
85
  // Initialize the plugin
86
  cordova.openwith.init(initSuccess, initError);
87
88
  function initSuccess()  { console.log('init success!'); }
89
  function initError(err) { console.log('init failed: ' + err); }
90
91
  // Define your file handler
92
  cordova.openwith.addHandler(myHandler);
93
94
  function myHandler(intent) {
95
    console.log('intent received');
96
    console.log('  text: ' + intent.text); // description to the sharing, for instance title of the page when shared URL from Safari
97
    for (var i = 0; i < intent.items.length; ++i) {
98
      var item = intent.items[i];
99
      console.log('  type: ', item.uti);    // UTI. possible values: public.url, public.text or public.image
100
      console.log('  type: ', item.type);   // Mime type. For example: "image/jpeg"
101
      console.log('  data: ', item.data);   // shared data. For text, it is the shared text string. For files, the file's URL on the device file system. You can read it from the webview with cordova-plugin-file or window.Ionic.WebView.convertFileSrc.
102
      console.log('  text: ', item.text);   // text to share alongside the item. as we don't allow user to enter text in native UI, in most cases this will be empty. However for sharing pages from Safari this might contain the title of the shared page.
103
      console.log('  name: ', item.name);   // suggested name of the image. For instance: "IMG_0404.JPG"
104
      console.log('  utis: ', item.utis);   // some optional additional info
105
    }
106
    // ...
107
    // Here, you probably want to do something useful with the data
108
    // ...
109
  }
110
```
111
112
- Codova run 
113
114
```
115
> cordova run ios
116
```
117
118
- Check consol log (Safari Web Inspector)
119
120
![](Screen Shot 7.png)