【问题标题】:Unity3D Push Notifications iOS & Android Vuforia & UrbanAirshipUnity3D 推送通知 iOS 和 Android Vuforia 和 UrbanAirship
【发布时间】:2014-09-09 16:19:03
【问题描述】:

我正在开发一个使用 Vuforia SDK 的游戏,我想最好使用 UrbanAirship 集成推送通知(这是我的客户要求的)

我一直在尝试让推送通知在 iOS 和 android 上都可以工作,但没有运气,不是使用 UrbanAirship,也不是任何其他方式,我还尝试了 Pushwoosh Unity 插件。

问题 1:UrbanAirship 是否可以与 Unity3d 集成?任何链接/建议/示例都会很棒,我已经搜索过但找不到任何相关内容。

问题 2:(如果我理解正确的话)是 Vurforia SDK 需要 Android Manifest 文件中的 MAIN 活动,因此我无法实现插件,例如 Pushwoosh 或其他类似插件,以使用 GCM(Google Cloud Messaging ) 他们也需要 MAIN 活动。

问题 3:如果我从我读过的所有网站/论坛/帖子中正确理解,GCM 是向 Android 推送通知的方式。阅读有关 GCM 的一些信息,它是一个通用的两个消息传递 API,它可以在应用程序未运行时用于推送通知吗?还是我完全走错了路?

我知道并为这个冗长的问题道歉,但这是第一次处理推送通知,更不用说在 iOS 和 Android 上都可以使用的东西了。我非常感谢任何有关如何使其正常工作的建议。蒂亚!

【问题讨论】:

  • wrt 1:我们也使用urbanairship,是的,它可以在另一个插件旁边使用,诀窍是附加到应用程序级别,而不是主要活动。
  • @Rudolfwm 谢谢,很高兴知道。您是否有机会按照您的建议发布如何将其附加到应用程序级别的示例? TIA!

标签: android ios unity3d push-notification vuforia


【解决方案1】:

这是我为 Urban Airship

构建的 android 插件的代码

请注意,我扩展了应用程序。您还需要一个意图接收器类。

package com.yourapp.urbanairship;

import android.app.Application;
import android.util.Log;

import com.urbanairship.AirshipConfigOptions;
import com.urbanairship.Logger;
import com.urbanairship.UAirship;
import com.urbanairship.push.CustomPushNotificationBuilder;
import com.urbanairship.push.PushManager;

public class UrbanAirShipPlugin extends Application {


    @Override
    public void onCreate() {

        super.onCreate();

        AirshipConfigOptions options = AirshipConfigOptions.loadDefaultOptions(this);

    options.productionAppKey ="XXXXXXXXXXXXXXXXXXXXXXXXXX";  // from urban airship
    options.productionAppSecret = "XXXXXXXXXXXXXXXXXXXXXXXXXX"; // from urban airship
    options.developmentAppKey ="XXXXXXXXXXXXXXXXXXXXXXXXXX"; // from urban airship
    options.developmentAppSecret = "XXXXXXXXXXXXXXXXXXXXXXXXXX";// from urban airship
    options.gcmSender = "XXXXXXXXXXXXXX"; // from GOOGLE -> basically your project id

    options.inProduction = true;
    options.analyticsEnabled =false;
    options.minSdkVersion=18;

    //determines which app key to use
    // Take off initializes the services
    UAirship.takeOff(this, options);
    PushManager.shared().setIntentReceiver(IntentReceiver.class);

    }
}

这是意图接收器类:

package your.package.name;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.urbanairship.UAirship;
import com.urbanairship.push.GCMMessageHandler;
import com.urbanairship.push.PushManager;

import java.util.Arrays;
import java.util.List;
import java.util.Set;

public class IntentReceiver extends BroadcastReceiver {

    private static final String logTag = "PushSample";

    public static String APID_UPDATED_ACTION_SUFFIX = ".apid.updated";

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.i(logTag, "Received intent: " + intent.toString());
        String action = intent.getAction();

        if (action.equals(PushManager.ACTION_PUSH_RECEIVED)) {

            int id = intent.getIntExtra(PushManager.EXTRA_NOTIFICATION_ID, 0);

            Log.i(logTag, "Received push notification. Alert: "
                + intent.getStringExtra(PushManager.EXTRA_ALERT)
                + " [NotificationID="+id+"]");

            logPushExtras(intent);

        } else if (action.equals(PushManager.ACTION_NOTIFICATION_OPENED)) {

            Log.i(logTag, "User clicked notification. Message: " + intent.getStringExtra(PushManager.EXTRA_ALERT));

            logPushExtras(intent);

            Intent launch = new Intent(Intent.ACTION_MAIN);
            launch.setClassName(UAirship.shared().getApplicationContext(), "your.main.activity" );
            launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            UAirship.shared().getApplicationContext().startActivity(launch);

        } else if (action.equals(PushManager.ACTION_REGISTRATION_FINISHED)) {
            Log.i(logTag, "Registration complete. APID:" + intent.getStringExtra(PushManager.EXTRA_APID)
                + ". Valid: " +     intent.getBooleanExtra(PushManager.EXTRA_REGISTRATION_VALID, false));

            // Notify any app-specific listeners
            Intent launch = new Intent(UAirship.getPackageName() + APID_UPDATED_ACTION_SUFFIX);
            UAirship.shared().getApplicationContext().sendBroadcast(launch);

        } else if (action.equals(GCMMessageHandler.ACTION_GCM_DELETED_MESSAGES)) {
            Log.i(logTag, "The GCM service deleted "+intent.getStringExtra(GCMMessageHandler.EXTRA_GCM_TOTAL_DELETED)+" messages.");
    }

}

/**
 * Log the values sent in the payload's "extra" dictionary.
 * 
 * @param intent A PushManager.ACTION_NOTIFICATION_OPENED or ACTION_PUSH_RECEIVED intent.
 */
    private void logPushExtras(Intent intent) {
        Set<String> keys = intent.getExtras().keySet();
        for (String key : keys) {

            //ignore standard C2DM extra keys
            List<String> ignoredKeys = (List<String>)Arrays.asList(
                "collapse_key",//c2dm collapse key
                "from",//c2dm sender
                PushManager.EXTRA_NOTIFICATION_ID,//int id of generated notification (ACTION_PUSH_RECEIVED only)
                PushManager.EXTRA_PUSH_ID,//internal UA push id
                PushManager.EXTRA_ALERT);//ignore alert
            if (ignoredKeys.contains(key)) {
                continue;
            }
            Log.i(logTag, "Push Notification Extra: ["+key+" : " + intent.getStringExtra(key) + "]");
        }
    }
}

还请注意,您需要将应用程序扩展的插件 com.yourapp.urbanairship 名称添加到清单中(在您需要的所有其他内容旁边):

<application android:allowClearUserData="true" android:icon="@drawable/app_icon" android:label="@string/app_name" android:name="com.yourapp.urbanairship"  android:debuggable="true">

并且不要忘记您的清单中还需要 Urbanairship 的其他任何内容(另请参阅 here

【讨论】:

  • 感谢您的回答,当我完成后,我将尝试在回帖中实现它。再次感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-01-24
  • 2016-04-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-18
  • 1970-01-01
相关资源
最近更新 更多