我终于有了我的智慧.我正在使用钛制的跨平台应用程序(IOS和Android),并通过休息电话连接到salesforce api.我在这个问题上花费了3天20个小时,而且仍然停滞不前.任何支持将非常感谢!所以让我们潜入.
我想要做什么:
应用程序启动,检查用户是否已经使用oauth2授权给了令牌,如果没有给用户salesforce登录屏幕.用户输入凭据并点击“允许”按钮,然后我们被重定向回应用程序.
问题:
从我想要做的上面的描述,除了粗体的最后一行之外,一切都起作用.一旦用户点击“允许”按钮,我们收到这个未知的url方案错误:
>我的index.js文件,这是salesforce登录调用的地方
>我的AuthService.js文件,它是在index.js中调用salesforce url信息的地方
>我的tiapp.xml,其中配置的东西被保存为android自定义url方案
index.js
var Auth = require('AuthService'); Auth.openLogin();
AuthService.js Only“openLogin”功能在这里非常重要.
var loginWindow; module.exports = { get: function () { console.log("made it into the auth.get function"); return Ti.App.Properties.getObject('auth'); },set: function (data) { Ti.App.Properties.setObject('auth',data); console.log("auth set function was executed!!!"); },erase: function () { Ti.App.Properties.removeProperty('auth'); },openLogin: function () { console.log("made it into openLogin!!"); var webview = Titanium.UI.createWebView({url:'https://login.salesforce.com/services/oauth2/authorize' + '?response_type=token&display=touch' + '&redirect_uri=testapp://app.open' + '&client_id=' + Ti.App.Properties.getString('salesforce_client_id')}); //console.log("Webview URL: " + webview.getUrl()); loginWindow = Titanium.UI.createWindow(); loginWindow.add(webview); loginWindow.open({modal:true}); // attempt to log url to console here //console.log("this is the webview URL during callback: " + webview.getUrl()); },closeLogin: function () { loginWindow.close(); } };
tiapp.xml我只是为了简洁而包含我的Android部分
<android xmlns:android="http://schemas.android.com/apk/res/android"> <manifest android:versionCode="1" android:versionName="1.00"> <uses-permission android:name="android.permission.INTERNET"></uses-permission> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission> </manifest> <activity android:name=".TesterActivity" android:exported="true" android:label="@string/app_name" > <intent-filter> <data android:host="app.open" android:scheme="testapp" /> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.BROWSABLE" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> </android>
与Salesforce注册的回调网址:
我试过了
在这个问题上,我已经把自己变蓝了.我修改的大部分内容都是调整我的“tiapp.xml”来改变android标签中这些属性的属性和值,以及对我的“AuthService.js”文件和salesforce中的“redirect_rui”值的许多调整“回调url”字段(因为这些值必须匹配或您得到一个uri不匹配错误).
以下是我为了解决我的问题而研究并尝试的一些解决方案:
https://gist.github.com/jasonkneen/5736738
How to implement my very own URI scheme on Android
仅举几例.
控制台登录应用程序执行:
[INFO] : Emulator is booted [INFO] : SD card not required,skipping mount check [INFO] : Emulator ready! [INFO] : Creating unsigned apk [INFO] : Processing /Users/michael.kellogg/Documents/Appcelerator_Studio_Workspace/tester/build/android/src [INFO] : Writing unsigned apk: /Users/michael.kellogg/Documents/Appcelerator_Studio_Workspace/tester/build/android/bin/app-unsigned.apk [INFO] : Using MD5withRSA signature algorithm [INFO] : Signing apk: /Library/Java/JavaVirtualMachines/jdk1.8.0_72.jdk/Contents/Home/bin/jarsigner "-sigalg" "MD5withRSA" "-digestalg" "SHA1" "-keystore" "/Users/michael.kellogg/Library/Application Support/Titanium/mobilesdk/osx/5.1.2.GA/android/dev_keystore" "-storepass" "*******" "-signedjar" "/Users/michael.kellogg/Documents/Appcelerator_Studio_Workspace/tester/build/android/bin/tester.apk" "/Users/michael.kellogg/Documents/Appcelerator_Studio_Workspace/tester/build/android/bin/app-unsigned.apk" "tidev" [INFO] : Aligning zip file: /Users/michael.kellogg/android-sdk/build-tools/23.0.2/zipalign "-v" "4" "/Users/michael.kellogg/Documents/Appcelerator_Studio_Workspace/tester/build/android/bin/tester.apk" "/Users/michael.kellogg/Documents/Appcelerator_Studio_Workspace/tester/build/android/bin/tester.apkz" [INFO] : Writing build manifest: /Users/michael.kellogg/Documents/Appcelerator_Studio_Workspace/tester/build/android/build-manifest.json [INFO] : Making sure the adb server is running [INFO] : Installing apk: /Users/michael.kellogg/Documents/Appcelerator_Studio_Workspace/tester/build/android/bin/tester.apk [INFO] : App successfully installed [INFO] : Starting app: com.test.test/.TesterActivity [INFO] : Application pid: 1160 [INFO] : Project built successfully in 3m 8s 295ms [INFO] : art: Late-enabling JIT [INFO] : art: JIT created with code_cache_capacity=2MB compile_threshold=1000 [INFO] : TiApplication: (main) [2,2] checkpoint,app created. [INFO] : TiApplication: (main) [1067,1069] Titanium 5.1.2 (2015/12/16 19:00 ca822b2) [INFO] : art: Background sticky concurrent mark sweep GC freed 15623(973KB) AllocSpace objects,11(384KB) LOS objects,41% free,2MB/3MB,paused 2.142ms total 105.631ms [INFO] : TiApplication: (main) [383,1452] Titanium Javascript runtime: v8 [INFO] : TiRootActivity: (main) [0,0] checkpoint,on root activity create,savedInstanceState: null [WARN] : TiTempFileHelper: (main) [189,189] The external temp directory doesn't exist,skipping cleanup [INFO] : TiRootActivity: (main) [0,on root activity resume. activity = com.test.test.TesterActivity@a298e02 [WARN] : V8Object: (KrollRuntimeThread) [1039,1228] Runtime disposed,cannot set property 'userAgent' [INFO] : made it into openLogin!! [INFO] : OpenGLRenderer: Initialized EGL,version 1.4 [WARN] : EGL_emulation: eglSurfaceAttrib not implemented [WARN] : OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xb4d32b20,error=EGL_SUCCESS [INFO] : WebViewFactory: Loading com.android.webview version 44.0.2403.119 (code 246011900) [WARN] : System: ClassLoader referenced unknown path: /system/app/webview/lib/arm [INFO] : LibraryLoader: Time to load native libraries: 36 ms (timestamps 588-624) [INFO] : LibraryLoader: Expected native library version number "",actual native library version number "" [INFO] : LibraryLoader: Expected native library version number "",actual native library version number "" [INFO] : chromium: [INFO:library_loader_hooks.cc(120)] Chromium logging enabled: level = 0,default verbosity = 0 [INFO] : BrowserStartupController: Initializing chromium process,singleProcess=true [WARN] : art: Attempt to remove non-JNI local reference,dumping thread [ERROR] : SysUtils: ApplicationContext is null in ApplicationStatus [WARN] : chromium: [WARNING:resource_bundle.cc(285)] locale_file_path.empty() [ERROR] : libEGL: validate_display:255 error 3008 (EGL_BAD_DISPLAY) [ERROR] : libEGL: validate_display:255 error 3008 (EGL_BAD_DISPLAY) [ERROR] : eglCodecCommon: glUtilsParamSize: unknow param 0x00008d57 [WARN] : AudioManagerAndroid: Requires BLUETOOTH permission [ERROR] : DataReductionProxySettingListener: No DRP key due to exception:java.lang.ClassNotFoundException: com.android.webview.chromium.Drp [WARN] : art: Attempt to remove non-JNI local reference,dumping thread [WARN] : AwContents: onDetachedFromWindow called when already detached. Ignoring [WARN] : art: Attempt to remove non-JNI local reference,dumping thread [WARN] : art: Attempt to remove non-JNI local reference,dumping thread [WARN] : chromium: [WARNING:data_reduction_proxy_config.cc(423)] SPDY proxy OFF at startup [WARN] : EGL_emulation: eglSurfaceAttrib not implemented [WARN] : OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xb4d32b40,error=EGL_SUCCESS [WARN] : art: Attempt to remove non-JNI local reference,dumping thread [INFO] : art: Background sticky concurrent mark sweep GC freed 7564(860KB) AllocSpace objects,25(988KB) LOS objects,0% free,11MB/11MB,paused 1.603ms total 308.766ms [WARN] : art: Attempt to remove non-JNI local reference,dumping thread [INFO] : art: Background partial concurrent mark sweep GC freed 1948(144KB) AllocSpace objects,3(8MB) LOS objects,22% free,13MB/17MB,paused 1.658ms total 271.298ms [WARN] : art: Attempt to remove non-JNI local reference,dumping thread [INFO] : art: Background partial concurrent mark sweep GC freed 148(6KB) AllocSpace objects,13(36MB) LOS objects,17% free,19MB/23MB,paused 1.205ms total 327.978ms [WARN] : art: Attempt to remove non-JNI local reference,dumping thread [INFO] : art: Background partial concurrent mark sweep GC freed 91(3KB) AllocSpace objects,5(14MB) LOS objects,paused 1.228ms total 201.595ms [WARN] : art: Attempt to remove non-JNI local reference,dumping thread [WARN] : art: Suspending all threads took: 15.737ms [INFO] : art: Background sticky concurrent mark sweep GC freed 261(13KB) AllocSpace objects,2(5MB) LOS objects,25MB/25MB,paused 18.832ms total 174.330ms [WARN] : art: Attempt to remove non-JNI local reference,dumping thread [INFO] : art: Background partial concurrent mark sweep GC freed 98(20KB) AllocSpace objects,7(19MB) LOS objects,26% free,11MB/15MB,paused 3.244ms total 302.681ms [WARN] : art: Attempt to remove non-JNI local reference,dumping thread [WARN] : BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 1160 [WARN] : art: Attempt to remove non-JNI local reference,dumping thread [INFO] : art: Background sticky concurrent mark sweep GC freed 11512(602KB) AllocSpace objects,0(0B) LOS objects,4% free,14MB/15MB,paused 1.739ms total 174.806ms [WARN] : art: Attempt to remove non-JNI local reference,dumping thread [INFO] : art: Background partial concurrent mark sweep GC freed 301(32KB) AllocSpace objects,25% free,paused 2.370ms total 274.103ms [WARN] : EGL_emulation: eglSurfaceAttrib not implemented [WARN] : OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x9d719f80,dumping thread [INFO] : art: Background sticky concurrent mark sweep GC freed 358(19KB) AllocSpace objects,17MB/17MB,paused 6.593ms total 277.832ms [WARN] : art: Attempt to remove non-JNI local reference,dumping thread [INFO] : art: Background partial concurrent mark sweep GC freed 148(5KB) AllocSpace objects,18% free,17MB/21MB,paused 7.547ms total 414.524ms [WARN] : art: Attempt to remove non-JNI local reference,dumping thread [INFO] : art: Background sticky concurrent mark sweep GC freed 30(608B) AllocSpace objects,1(2MB) LOS objects,23MB/23MB,paused 2.321ms total 159.615ms [WARN] : art: Attempt to remove non-JNI local reference,dumping thread [INFO] : art: Background partial concurrent mark sweep GC freed 36(1168B) AllocSpace objects,21% free,14MB/18MB,paused 1.626ms total 197.175ms [WARN] : art: Attempt to remove non-JNI local reference,dumping thread [INFO] : art: Background sticky concurrent mark sweep GC freed 21(448B) AllocSpace objects,20MB/20MB,paused 37.280ms total 96.680ms [INFO] : art: Background partial concurrent mark sweep GC freed 34(960B) AllocSpace objects,4(11MB) LOS objects,30% free,8MB/12MB,paused 1.475ms total 106.381ms [WARN] : art: Attempt to remove non-JNI local reference,dumping thread [INFO] : art: Background partial concurrent mark sweep GC freed 56(3KB) AllocSpace objects,paused 3.001ms total 243.577ms [WARN] : art: Attempt to remove non-JNI local reference,dumping thread [WARN] : BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 1160 [WARN] : BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 1160 [WARN] : BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 1160 [INFO] : I/TiWebChromeClient.console: (main) [21796,21796] Not allowed to load local resource: file:///android_asset/webkit/android-weberror.png (0:data:text/html,chromewebdata) [INFO] : art: Background sticky concurrent mark sweep GC freed 337(53KB) AllocSpace objects,6% free,17MB/18MB,paused 43.249ms total 82.260ms [WARN] : art: Attempt to remove non-JNI local reference,dumping thread [INFO] : art: Background partial concurrent mark sweep GC freed 82(11KB) AllocSpace objects,paused 1.613ms total 159.713ms [WARN] : art: Attempt to remove non-JNI local reference,dumping thread [INFO] : art: Background sticky concurrent mark sweep GC freed 27(544B) AllocSpace objects,paused 21.912ms total 68.965ms [WARN] : art: Attempt to remove non-JNI local reference,dumping thread [INFO] : art: Background partial concurrent mark sweep GC freed 39(1056B) AllocSpace objects,paused 1.523ms total 136.698ms [WARN] : art: Attempt to remove non-JNI local reference,dumping thread [ERROR] : Surface: getSlotFromBufferLocked: unknown buffer: 0xaad48dc0 [INFO] : art: Background partial concurrent mark sweep GC freed 40(1104B) AllocSpace objects,paused 3.871ms total 157.623ms [INFO] : APSAnalyticsService: Analytics Service Started [INFO] : APSAnalyticsService: Stopping Analytics Service -- End application log -------------------------------------------------------
解决方法
问题:在销售人员授权(自定义url方案对Android非常痛苦)后,无法找到方法导航回android应用程序.
解决方案:在搜索之后,我发现一个代码示例来自salesforce,这是我在这里尝试做的:
这是上述文章中提供的github链接,其中包含了非常需要的代码:
https://github.com/appcelerator-developer-relations/Force
TLDR:这里的真正的关键是不要使用android和钛的自定义url方案.相反,上面列出的github代码在Web视图中打开了auth页面,然后使用侦听器在完成验证后关闭该Webview,并打开所需的任何视图.
说明:在IOS上导航回我的应用程序,我只需要添加几行到我的tiapp.xml文件,以便使用自定义的url方案.它的工作非常快速和简单,没有任何头痛.自然,我假设一个自定义的url方案是去android的方式,简单对吗?假.我花了很多小时,如上所述,试图在android上制作一个自定义的url方案无效.似乎有很多关于android自定义url计划的信息在线,但没有一个为我工作,相信我尝试了这么多事情(毕竟是大约64小时).最终,我只是试图找到一个在线代码的例子.这是我发现的.