diff --git a/.gitignore b/.gitignore index 6fabe323..25686872 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,5 @@ ios/build # OS X Icon Thumbs.db -.DS_Store \ No newline at end of file +.DS_Store +ios/DerivedData diff --git a/actionscript/src/com/freshplanet/nativeExtensions/PushNotification.as b/actionscript/src/com/freshplanet/nativeExtensions/PushNotification.as index 248670c2..bf665e85 100644 --- a/actionscript/src/com/freshplanet/nativeExtensions/PushNotification.as +++ b/actionscript/src/com/freshplanet/nativeExtensions/PushNotification.as @@ -5,8 +5,6 @@ package com.freshplanet.nativeExtensions import flash.events.StatusEvent; import flash.external.ExtensionContext; import flash.system.Capabilities; - - import mx.graphics.shaderClasses.ExclusionShader; public class PushNotification extends EventDispatcher @@ -75,6 +73,14 @@ package com.freshplanet.nativeExtensions extCtx.call("registerPush", projectId); } } + + public function unregisterPushNotification() : void + { + if (this.isPushNotificationSupported) + { + extCtx.call("unregisterPush"); + } + } public function setBadgeNumberValue(value:int):void { diff --git a/android/src/com/freshplanet/nativeExtensions/C2DMExtensionContext.java b/android/src/com/freshplanet/nativeExtensions/C2DMExtensionContext.java index 01b3399f..110edb31 100644 --- a/android/src/com/freshplanet/nativeExtensions/C2DMExtensionContext.java +++ b/android/src/com/freshplanet/nativeExtensions/C2DMExtensionContext.java @@ -49,6 +49,7 @@ public Map getFunctions() { Log.d(TAG, "C2DMExtensionContext.getFunctions"); Map functionMap = new HashMap(); functionMap.put("registerPush", new C2DMRegisterFunction()); + functionMap.put("unregisterPush", new C2DMUnregisterFunction()); functionMap.put("setBadgeNb", new SetBadgeValueFunction()); functionMap.put("sendLocalNotification", new LocalNotificationFunction()); functionMap.put("setIsAppInForeground", new SetIsAppInForegroundFunction()); diff --git a/android/src/com/freshplanet/nativeExtensions/C2DMUnregisterFunction.java b/android/src/com/freshplanet/nativeExtensions/C2DMUnregisterFunction.java new file mode 100644 index 00000000..1d82c40c --- /dev/null +++ b/android/src/com/freshplanet/nativeExtensions/C2DMUnregisterFunction.java @@ -0,0 +1,64 @@ +////////////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2012 Freshplanet (http://freshplanet.com | opensource@freshplanet.com) +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +////////////////////////////////////////////////////////////////////////////////////// + +package com.freshplanet.nativeExtensions; + +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.os.Build; +import android.util.Log; + +import com.adobe.fre.FREContext; +import com.adobe.fre.FREFunction; +import com.adobe.fre.FREObject; + +/** + * Register the app for push notification + * + * @author titi + * + */ +public class C2DMUnregisterFunction implements FREFunction { + + private static String TAG = "c2dmUnregister"; + + + public FREObject call(FREContext context, FREObject[] args) + { + if(Build.MANUFACTURER.equals("Amazon")) { + Log.d(TAG, "push notifications disabled on amzon devices, ignoring register"); + return null; + } + + Context appContext = context.getActivity().getApplicationContext(); + Log.d(TAG, "C2DMUnregisterFunction.call"); + try { + + Intent unregistrationIntent = new Intent("com.google.android.c2dm.intent.UNREGISTER"); + unregistrationIntent.putExtra("app", PendingIntent.getBroadcast(appContext, 0, new Intent(), 0)); + appContext.startService(unregistrationIntent); + + } catch (Exception e) { + Log.e(TAG, "Error sending unregistration intent.", e); + } + return null; + } + + +} diff --git a/bin/AirPushNotification.ane b/bin/AirPushNotification.ane index 2781f7d3..b641b999 100644 Binary files a/bin/AirPushNotification.ane and b/bin/AirPushNotification.ane differ diff --git a/ios/AirPushNotification/AirPushNotification.h b/ios/AirPushNotification/AirPushNotification.h index 722e7a08..cfc6a66e 100644 --- a/ios/AirPushNotification/AirPushNotification.h +++ b/ios/AirPushNotification/AirPushNotification.h @@ -31,6 +31,7 @@ void didRegisterForRemoteNotificationsWithDeviceToken(id self, SEL _cmd, UIAppli void didFailToRegisterForRemoteNotificationsWithError(id self, SEL _cmd, UIApplication* application, NSError* error); FREObject setBadgeNb(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]); FREObject registerPush(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]); +FREObject unregisterPush(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]); FREObject sendLocalNotification(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]); FREObject setIsAppInForeground(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]); diff --git a/ios/AirPushNotification/AirPushNotification.m b/ios/AirPushNotification/AirPushNotification.m index 963b4c01..e92042fe 100644 --- a/ios/AirPushNotification/AirPushNotification.m +++ b/ios/AirPushNotification/AirPushNotification.m @@ -44,7 +44,7 @@ - (void)application:(UIApplication *)application didReceiveRemoteNotification:(N void didRegisterForRemoteNotificationsWithDeviceToken(id self, SEL _cmd, UIApplication* application, NSData* deviceToken) { NSString* tokenString = [NSString stringWithFormat:@"%@", deviceToken]; - NSLog(@"My token is: %@", deviceToken); + //NSLog(@"My token is: %@", deviceToken); if ( myCtx != nil ) { @@ -125,6 +125,15 @@ void didReceiveRemoteNotification(id self, SEL _cmd, UIApplication* application, return nil; } +// unregisters the device for push notification. +DEFINE_ANE_FUNCTION(unregisterPush) +{ + + [[UIApplication sharedApplication] unregisterForRemoteNotifications]; + return nil; +} + + // register the device for push notification. DEFINE_ANE_FUNCTION(setIsAppInForeground) { @@ -244,7 +253,7 @@ void AirPushContextInitializer(void* extData, const uint8_t* ctxType, FREContext ///////// end of delegate injection / modification code // Register the links btwn AS3 and ObjC. (dont forget to modify the nbFuntionsToLink integer if you are adding/removing functions) - NSInteger nbFuntionsToLink = 4; + NSInteger nbFuntionsToLink = 5; *numFunctionsToTest = nbFuntionsToLink; FRENamedFunction* func = (FRENamedFunction*) malloc(sizeof(FRENamedFunction) * nbFuntionsToLink); @@ -265,6 +274,11 @@ void AirPushContextInitializer(void* extData, const uint8_t* ctxType, FREContext func[3].functionData = NULL; func[3].function = &setIsAppInForeground; + func[4].name = (const uint8_t*) "unregisterPush"; + func[4].functionData = NULL; + func[4].function = &unregisterPush; + + *functionsToSet = func; myCtx = ctx; @@ -275,9 +289,9 @@ void AirPushContextInitializer(void* extData, const uint8_t* ctxType, FREContext // Set when the context extension is created. void AirPushContextFinalizer(FREContext ctx) { - NSLog(@"Entering ContextFinalizer()"); + //NSLog(@"Entering ContextFinalizer()"); - NSLog(@"Exiting ContextFinalizer()"); + //NSLog(@"Exiting ContextFinalizer()"); } @@ -290,13 +304,13 @@ void AirPushContextFinalizer(FREContext ctx) { void AirPushExtInitializer(void** extDataToSet, FREContextInitializer* ctxInitializerToSet, FREContextFinalizer* ctxFinalizerToSet ) { - NSLog(@"Entering ExtInitializer()"); + //NSLog(@"Entering ExtInitializer()"); *extDataToSet = NULL; *ctxInitializerToSet = &AirPushContextInitializer; *ctxFinalizerToSet = &AirPushContextFinalizer; - NSLog(@"Exiting ExtInitializer()"); + //NSLog(@"Exiting ExtInitializer()"); } void AirPushExtFinalizer(void *extData) { } \ No newline at end of file