顯示具有 iOS notification 標籤的文章。 顯示所有文章
顯示具有 iOS notification 標籤的文章。 顯示所有文章

2012年12月16日 星期日

推播音效任我訂,尖叫尖笑都可行 ( 彼得潘App程式設計第101式)



UILocalNotification物件有個NSString型別的soundName property,正是讓我們設定音效的。UILocalNotificationDefaultSoundName將播放內建的提醒音效,也就是我們收到簡訊時聽到的聲音。


    UILocalNotification *localNotification = [[UILocalNotification alloc] init];

   localNotification.soundName = UILocalNotificationDefaultSoundName;

除了內建的音效,我們也可以自訂音效,不管是嚇死人的驚聲尖叫還是笑死人的驚聲尖笑都可以,只要將soundName指定為音效檔的檔名(記得要事先將音效檔加到專案裡),例如以下程式碼:

       localNotification.soundName = @"test.wav";



不過對於推播的音效檔,Apple倒是有以下2點限制:
a. 檔案必須是caf, wav或是aiff格式。
b. 聲音長度必須少於30秒,否則將播放內建的提醒音效。

若是指定的soundName檔案不存在,也會播放內建的提醒音效。

一般我們經由iTunes將CD存入Mac的音樂都是m4a的格式,若是想轉為推播格式,可於Terminal輸入以下指令輸出caf檔。

    afconvert  你就是我要的.m4a  你就是我要的.caf -d ima4 -f caff –v

2011年4月15日 星期五

NSNotificationCenter

- (void)addObserver:(id)observer selector:(SEL)aSelector :(NSString *)aName object:(id)anObject;
register to receive notification
parameter:
1. observer: the object to receive notification

2. aName: name of notification, if it is nil, we receive all notifications sent out by anObject

3. anObject: specify object we want to observe. If it is nil, we receive all notification with aName

we can register many objects to receive same notification.


- (void)postNotificationName:(NSString *)aName object:(id)anObject;
send notfication
parameter:
anObject: sender




2011年3月27日 星期日

sandbox & production environment for iOS push

sandbox environment:
1. provisioning profile
    development provisioning profile
    provisioning profile以iPhone Developer開頭
2. Apple server:
    gateway.push.apple.com
3. certificate
    Development Push SSL Certificate


production environment
1. provisioning profile
    distribution provision profile (ad-hoc or App store)
    provisioning profile以iPhone Distribution開頭
2. Apple server:
   gateway.sandbox.push.apple.com
3. certificate
   Production Push SSL Certificate

provisioning profile for push notification

can not use wildcard App ID
( However, in app purchase's provisioning profile can use wildcard App ID)

當provisioning profile對到的App ID有enable push時,
provisioning profile裡將包含aps-environment這組key。
(使用text editor打開provisioning profile即可檢查。)

2011年3月25日 星期五

notification on iOS and Cocoa

注冊接收notification
ex:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(test:) name:@"TEST_NOTIFICATION" object:nil];
addObserver: 接收notification的物件
object: 有興趣的對象,也就是發出notification的對象。nil表示不限對象。


2011年3月21日 星期一

push by Urban Airship

API reference:
http://urbanairship.com/docs/push.html

利用curl發送broadcast
curl -X POST -u "abcd:defg" -H "Content-Type: application/json" --data '{"aps":{"alert":"hello"}}' https://go.urbanairship.com/api/push/broadcast/
說明:
abcd是app key, defg是app master secret

利用curl發送push:
curl -X POST -u "abcd:defg" -H "Content-Type: application/json" --data '{"device_tokens":["BDD076692A89126ED3C5EA057F7C253534807D6F30C04FB67F01FCDD5BDDCB7B"] , "aps":{"alert":"hello"}}' https://go.urbanairship.com/api/push/
說明:
BDD076692A89126ED3C5EA057F7C253534807D6F30C04FB67F01FCDD5BDDCB7B is device token

在iOS device上使用urban airship提供的library
reference:
http://urbanairship.com/docs/apns_test_client.html

2011年3月19日 星期六