반응형

스토어로 이동

-안드로이드

https://play.google.com/store/apps/details?id=com.your.appname

 

-아이폰

https://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=12341234yourid

itms-apps://itunes.apple.com/kr/app/apple-store/{app이름}

if (UIApplication.main.canOpen){
  if let appUrl = URL(string: "itms-apps://itunes.apple.com/kr/app/apple-store/{app이름}") { 
    if UIApplication.shared.canOpenURL(appUrl) { 
        UIApplication.shared.openURL(appUrl)
    } 
    else{
   		 //안열릴때 처리
    }
  }
}

 

앱스키마로 앱실행시 처리

*안드로이드

 

요청하는 부분

String uriData = schemeName+"://"+uriData;
Uri uri = Uri.parse(uriData);
Intent i = new Intent(Intent.ACTION_VIEW);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.setData(uri);
startActivity(i);

- uriData는 이런식으로 되있다. - > myScheme://action?url='yoururl'

 

 

받는 부분

<application>
		....
      <activity
            android:name=".ui.MainActivity"
            android:screenOrientation="portrait"
            android:theme="@style/AppTheme.Base"
            android:windowSoftInputMode="adjustPan">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data
                    android:host="action"
                    android:scheme="myScheme" />
            </intent-filter>
        </activity>
        ....
</application>

 

<data android:host="action"
	  android:scheme="myScheme" />

- host : 빨간색

  scheme : 파란색

 

  myScheme://action?url='yoururl'

 

 

스키마처리 ..

   public void checkExternalAppschema2(){
        Logger.d(TAG,"## checkExternalAppschema!!");
        //다른앱에서 실행시킬때 받을 인텐트
        Intent schemeIntent = getIntent();
        if (schemeIntent.getAction() != null){
            if (Intent.ACTION_VIEW.equals(schemeIntent.getAction())) {
                Uri uri = null;
                uri = schemeIntent.getData();
                if(uri != null) {
                    app_schema_url = uri.getQueryParameter("url");

                    // 파라미터가 있을때.
                    if (app_schema_url != null){
                        new Handler().postDelayed(new Runnable() {
                            @Override
                            public void run() {
                              //  파라미터가 있을때 처리 ...
                            }
                        }, 500);

                        try{
                            getIntent().replaceExtras(new Bundle());
                            getIntent().setAction("");
                            getIntent().setData(null);
                            getIntent().setFlags(0);
                        }catch (NullPointerException e){
                            e.printStackTrace();
                        }
                    }
                    //파라미터가 없을시
                    else {
                       //  파라미터가 없을시 처리 ...
                    }
                }
            }
        } 
    }

 

app_schema_url = uri.getQueryParameter("url");

- 쿼리파라미터 키,벨류 ; 초록색

   myScheme://action?url='yoururl'

 

 

getIntent().replaceExtras(new Bundle());
getIntent().setAction("");
getIntent().setData(null);
getIntent().setFlags(0);

- 초기화 안시켜주면 한번더 요청이 왔을때 작동을 안한다.

 

 

 

 

 

*아이폰

보내는쪽

            if let appurl = URL(string: "yourapp://") {
                if  UIApplication.shared.canOpenURL(appurl){
                    UIApplication.shared.open(appurl, options: .init()) { (finished) in
                        if finished {
                            print("finished !!")
                        }
                    }
                }
            }

받는쪽

  func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    if let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false) {
      if let queryItems = urlComponents.queryItems {
        if let top = topView() {
          nToast.show(top, msg: "queryItems: \(queryItems.description)")
          
//          let key = queryItems.first?.name
//          let val = queryItems.first?.value
//          queryItems.forEach { item in }
        }
      }
    }
    
    //다른앱에서 오픈했을때.
    if let otherApp = options[.sourceApplication] as? String {
        logi("\(TAG) open url sending App ID = \(otherApp)")
    }
    //safari에서 오픈했을때.
    else {
         logi("\(TAG) open url safari ")
    }
    
    
    
    return true
  }
반응형

+ Recent posts